fastify-jwt
fastify-jwt copied to clipboard
Typescript issue: No overload matches this call.
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.2.0
Plugin version
6.2.1
Node.js version
16.10.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
12.4
Description
Hi, I get the TS error
No overload matches this call.
Overload 2 of 3, '(plugin: FastifyPluginAsync<FastifyJWTOptions, Server, FastifyTypeProviderDefault>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'FastifyPluginCallback<FastifyJWTOptions, Server, FastifyTypeProviderDefault>' is not assignable to parameter of type 'FastifyPluginAsync<FastifyJWTOptions, Server, FastifyTypeProviderDefault>'
The code is this:
import fastifyJwt, { FastifyJWTOptions } from '@fastify/jwt';
import fp from 'fastify-plugin';
export default fp<FastifyJWTOptions>(async fastify => {
fastify.register(fastifyJwt, {
secret: process.env.MICROSOFT_CLIENT_SECRET,
sign: { algorithms: ['RS256'] },
});
});
Expected Behavior
I expect that the type works.
Thanks!
cc @Eomm
Thanks for reporting!
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
I could not reproduce this. I actually got a implementation error
import fastifyJwt, { FastifyJWTOptions } from '@fastify/jwt';
import fp from 'fastify-plugin';
export default fp<FastifyJWTOptions>(async fastify => {
fastify.register(fastifyJwt, {
secret: process.env.MICROSOFT_CLIENT_SECRET! as string,
sign: { algorithm: 'RS256' }, // you used algoritmhm, which is not right
});
});
This transpiles well
I had the same error when I forgot the non null assertion when providing environment variables to the secret
property.
Just change process.env.MICROSOFT_CLIENT_SECRET
to process.env.MICROSOFT_CLIENT_SECRET! as string
@Manubi Did @Uzlopak's solution resolve this?