-
-
Notifications
You must be signed in to change notification settings - Fork 45
Closed
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.3.0
Plugin version
4.1.0
Node.js version
18.7.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Fedora Workstation 36
Description
The default export fp only allows a Options generic. This means you cannot pass in a function of type FastifyPluginAsync<MyOptions, MyRawServer, MyTypeProvider> for instance. I believe you should be able to pass in the two other generics as it has some use cases, in my case creating a package that can accept any RawServer type.
This results in a ts error like this:
Argument of type 'FastifyPluginAsync<Options, RawServer, FastifyTypeProviderDefault>' is not assignable to parameter of type 'FastifyPluginCallback<Options, Server, FastifyTypeProviderDefault>'.
Types of parameters 'instance' and 'instance' are incompatible.
...
This is the types I believe would fix this, happy to make a pull request.
export default function fp<
Options extends FastifyPluginOptions = Record<never, never>,
Server extends RawServerBase = RawServerDefault,
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
>(
fn: FastifyPluginAsync<Options, Server, TypeProvider>,
...
): FastifyPluginAsync<Options, Server, TypeProvider>Steps to Reproduce
Pass in a function of type FastifyPluginAsync<MyOptions, MyRawServer, MyTypeProvider> to the fp function.
Expected Behavior
You should be able to pass in the generics manually or be inferred.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels