You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect that, as explained in the docs, I would be able to do something like that:
// Here we will use the `hello` named instancefastify.get('/hello',(req,reply)=>{const{ redis }=fastifyredis.hello.get(req.query.key,(err,val)=>{reply.send(err||val)})})fastify.post('/hello',(req,reply)=>{const{ redis }=fastifyredis['hello'].set(req.body.key,req.body.value,(err)=>{reply.send(err||{status: 'ok'})})})// Here we will use the `world` named instancefastify.get('/world',(req,reply)=>{const{ redis }=fastifyredis['world'].get(req.query.key,(err,val)=>{reply.send(err||val)})})
But whenever I try to access redis['hello'] TypeScript complains about that with the following error:
Element implicitly has an 'any' type because expression of type '"hello"' can't be used to index type 'Redis'.
Property 'hello' does not exist on type 'Redis'.
I thought that maybe I would have been able to fix this issue by myself doing that, albeit this is not documented anywhere:
But this time TypeScript greets me with this error:
Subsequent property declarations must have the same type. Property 'redis' must be of type 'Redis', but here has type '{ test: Redis; test2: Redis; }'.
Prerequisites
Fastify version
3.19.2
Plugin version
4.3.1
Node.js version
v14.16.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
11.4
Description
I'm trying to register multiple Redis client instances as follow:
I would expect that, as explained in the docs, I would be able to do something like that:
But whenever I try to access
redis['hello']
TypeScript complains about that with the following error:I thought that maybe I would have been able to fix this issue by myself doing that, albeit this is not documented anywhere:
But this time TypeScript greets me with this error:
So this seems a dead end to me.
Can someone shed a light on this for me?
Thanks in advance.
Steps to Reproduce
Just follow the Registering multiple Redis client instances step in Readme.MD with a project bootstrapped with fastify-cli and
TypeScript
.Expected Behavior
I expect that one can register multiple Redis instances and correctly access them, even when using
TypeScript
.The text was updated successfully, but these errors were encountered: