Skip to content

Type error in setupFastifyErrorHandler #18619

Description

@OliverRM

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

  1. Set up Fastify and TypeScript
  2. Enable TypeScript feature exactOptionalPropertyTypes
  3. Use Sentry.setupFastifyErrorHandler

Expected Result

No type errors

Actual Result

The following type error occurs:

error TS2345: Argument of type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault> & PromiseLike<...> & { ...; }' is not assignable to parameter of type 'FastifyInstance'.
  The types of 'register(...).addHook' are incompatible between these types.
    Type '{ <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = unknown, SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger, Fn extends onRequestAsyncHookHandler<...> | onRequestHookHandler<...> = onRequestHookHandler<...>>(name: "onReque...' is not assignable to type '{ (hook: string, handler: HandlerOriginal): FastifyInstance; (hook: "onError", handler: (request: FastifyRequest, reply: FastifyReply, error: Error) => void): FastifyInstance; (hook: "onRequest", handler: (request: FastifyRequest, reply: FastifyReply) => void): FastifyInstance; }'.
      Types of parameters 'hook' and 'handler' are incompatible.
        Type 'HandlerOriginal' is not assignable to type 'onRequestAsyncHookHandler<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, ... 4 more ..., any> | onRequestHookHandler<...>'.
          Type '(request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => Promise<void>' is not assignable to type 'onRequestAsyncHookHandler<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, ... 4 more ..., any> | onRequestHookHandler<...>'.
            Type '(request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => Promise<void>' is not assignable to type 'onRequestAsyncHookHandler<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, ... 4 more ..., any>'.
              Target signature provides too few arguments. Expected 3 or more, but got 2.

See https://github.com/OliverRM/sentry-fastify-type-error for a minimal failing example.

Product Area

Unknown

Link

No response

DSN

No response

Version

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions