Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastifyRegister type does not propagate type provider generic to plugin type #4032

Closed
2 tasks done
stefee opened this issue Jun 17, 2022 · 6 comments · Fixed by #4034
Closed
2 tasks done

FastifyRegister type does not propagate type provider generic to plugin type #4032

stefee opened this issue Jun 17, 2022 · 6 comments · Fixed by #4034

Comments

@stefee
Copy link
Contributor

stefee commented Jun 17, 2022

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.x.x

Plugin version

No response

Node.js version

16.x

Operating system

macOS

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

11.6

Description

The FastifyRegister type (of fastify.register function) has this interface:

export interface FastifyRegister<T = void> {
  <Options extends FastifyPluginOptions>(
    plugin: FastifyPluginCallback<Options>,
    opts?: FastifyRegisterOptions<Options>
  ): T;
  <Options extends FastifyPluginOptions>(
    plugin: FastifyPluginAsync<Options>,
    opts?: FastifyRegisterOptions<Options>
  ): T;
  <Options extends FastifyPluginOptions>(
    plugin: FastifyPluginCallback<Options> | FastifyPluginAsync<Options> | Promise<{ default: FastifyPluginCallback<Options> }> | Promise<{ default: FastifyPluginAsync<Options> }>,
    opts?: FastifyRegisterOptions<Options>
  ): T;
}

This passes through the Options to the plugin but not the other arguments (Server and TypeProvider) which results in an error like this:

No overload matches this call.
  Overload 1 of 3, '(plugin: FastifyPluginCallback<Record<never, never>, http.Server, FastifyTypeProviderDefault>, opts?: FastifyRegisterOptions<Record<never, never>> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'FastifyPluginAsync<Record<never, never>, http.Server, TypeBoxTypeProvider>' is not assignable to parameter of type 'FastifyPluginCallback<Record<never, never>, http.Server, FastifyTypeProviderDefault>'.
      Types of parameters 'instance' and 'instance' are incompatible.
        Type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, FastifyTypeProviderDefault>' is not assignable to type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, TypeBoxTypeProvider>'.
          The types returned by 'after()' are incompatible between these types.
            Type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, FastifyTypeProviderDefault> & PromiseLike<undefined>' is not assignable to type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, TypeBoxTypeProvider> & PromiseLike<undefined>'.
              Type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, FastifyTypeProviderDefault> & PromiseLike<undefined>' is not assignable to type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, TypeBoxTypeProvider>'.
                Types of property 'register' are incompatible.
                  Type 'FastifyRegister<FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, FastifyTypeProviderDefault> & PromiseLike<undefined>>' is not assignable to type 'FastifyRegister<FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, TypeBoxTypeProvider> & PromiseLike<undefined>>'.
                    Type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, FastifyTypeProviderDefault> & PromiseLike<undefined>' is not assignable to type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, TypeBoxTypeProvider> & PromiseLike<undefined>'.
                      Type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, FastifyTypeProviderDefault> & PromiseLike<undefined>' is not assignable to type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, TypeBoxTypeProvider>'.
                        The types of 'addSchema(...).get' are incompatible between these types.
                          Type 'RouteShorthandMethod<http.Server, http.IncomingMessage, http.ServerResponse, FastifyTypeProviderDefault>' is not assignable to type 'RouteShorthandMethod<http.Server, http.IncomingMessage, http.ServerResponse, TypeBoxTypeProvider>'.
                            Type 'FastifyTypeProviderDefault' is not assignable to type 'TypeBoxTypeProvider'.
  Overload 2 of 3, '(plugin: FastifyPluginAsync<Record<never, never>, http.Server, FastifyTypeProviderDefault>, opts?: FastifyRegisterOptions<Record<never, never>> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'FastifyPluginAsync<Record<never, never>, http.Server, TypeBoxTypeProvider>' is not assignable to parameter of type 'FastifyPluginAsync<Record<never, never>, http.Server, FastifyTypeProviderDefault>'.
      Types of parameters 'instance' and 'instance' are incompatible.
        Type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, FastifyTypeProviderDefault>' is not assignable to type 'FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyLoggerInstance, TypeBoxTypeProvider>'.
  Overload 3 of 3, '(plugin: FastifyPluginCallback<Record<never, never>, http.Server, FastifyTypeProviderDefault> | FastifyPluginAsync<Record<never, never>, http.Server, FastifyTypeProviderDefault> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'FastifyPluginAsync<Record<never, never>, http.Server, TypeBoxTypeProvider>' is not assignable to parameter of type 'FastifyPluginCallback<Record<never, never>, http.Server, FastifyTypeProviderDefault> | FastifyPluginAsync<Record<never, never>, http.Server, FastifyTypeProviderDefault> | Promise<...> | Promise<...>'.
      Type 'FastifyPluginAsync<Record<never, never>, http.Server, TypeBoxTypeProvider>' is not assignable to type 'FastifyPluginAsync<Record<never, never>, http.Server, FastifyTypeProviderDefault>'.

Steps to Reproduce

See https://github.com/stefee/fastify-issue-repro-4032/blob/main/index.ts

Expected Behavior

No type error.

@RafaelGSS
Copy link
Member

@stefee the repository seems private, can you move it to the public so I can see the reproduction?

@stefee
Copy link
Contributor Author

stefee commented Jun 17, 2022

@RafaelGSS Fixed!

@keysking
Copy link

@RafaelGSS Fixed!
I have the same problem
Can you tell me how you solved it?

@keysking
Copy link

@RafaelGSS Fixed!
I have the same problem
Can you tell me how you solved it?

Sorry, I didn't just see that PR, so I just need to wait for the RELEASE, right?

@stefee
Copy link
Contributor Author

stefee commented Jun 18, 2022

Issue isn’t fixed yet - the broken link in the description is. Fix incoming.

@stefee
Copy link
Contributor Author

stefee commented Jun 19, 2022

@keysking The fix should come in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants