fastify / fastify-auth

Run multiple auth functions in Fastify
Other
341 stars 56 forks source link

No overload matches for fastify plugin #201

Closed michelle54725 closed 1 year ago

michelle54725 commented 1 year ago

Prerequisites

Fastify version

4.21.0

Plugin version

4.3.0

Node.js version

18.x

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

Monterey

Description

Trying to migrate JS->TS for a NodeJS backend service. After changing index.js -> index.ts all my fastify plugins are fine (e.g. FastifyOpenapiDocs, FastifyMultipart, FastifySentry), but FastifyAuth has this error:

No overload matches this call.
  Overload 1 of 3, '(plugin: FastifyPluginCallback<{ defaultRelation: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'typeof fastifyAuth' is not assignable to parameter of type 'FastifyPluginCallback<{ defaultRelation: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
      Type 'typeof fastifyAuth' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
      Type 'typeof fastifyAuth' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProvider>, opts: { ...; }, done: (err?: Error) => void): void'.
  Overload 2 of 3, '(plugin: FastifyPluginAsync<{ defaultRelation: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'typeof fastifyAuth' is not assignable to parameter of type 'FastifyPluginAsync<{ defaultRelation: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
      Type 'typeof fastifyAuth' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProvider>, opts: { ...; }): Promise<...>'.
  Overload 3 of 3, '(plugin: FastifyPluginCallback<{ defaultRelation: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger> | FastifyPluginAsync<...> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...>): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'typeof fastifyAuth' is not assignable to parameter of type 'FastifyPluginCallback<{ defaultRelation: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger> | FastifyPluginAsync<...> | Promise<...> | Promise<...>'.ts(2769)

Steps to Reproduce

Code looks something like:

// index.ts
import * as FastifyAuth from '@fastify/auth';

fastify.decorate('authfunc1', authfunc1);
fastify.decorate('authfunc2', authfunc2);
await fastify.register(FastifyAuth, { defaultRelation: 'and' }); //error under `FastifyAuth`

Expected Behavior

No response

Uzlopak commented 1 year ago
import { fastify as Fastify } from "fastify"
import { fastifyAuth } from '@fastify/auth';

const fastify = Fastify({})
await fastify.register(fastifyAuth, { defaultRelation: 'and' }); //error under `FastifyA