fastify-jwt icon indicating copy to clipboard operation
fastify-jwt copied to clipboard

Typescript issue: No overload matches this call.

Open Manubi opened this issue 2 years ago • 3 comments

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: CleanShot 2022-07-07 at 14 21 46@2x

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!

Manubi avatar Jul 07 '22 12:07 Manubi

cc @Eomm

mcollina avatar Jul 07 '22 12:07 mcollina

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.

mcollina avatar Jul 07 '22 22:07 mcollina

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

Uzlopak avatar Aug 02 '22 14:08 Uzlopak

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

pbell23 avatar Jan 12 '23 21:01 pbell23

@Manubi Did @Uzlopak's solution resolve this?

Fdawgs avatar Mar 14 '23 21:03 Fdawgs