Skip to content

typings for the route config based hooks no longer working since 4.16.0 #4705

@vidarc

Description

@vidarc

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

Plugin version

No response

Node.js version

18.x

Operating system

macOS

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

12.3

Description

The hooks specified in the options of a route no longer have the correct typings applied/resolved. They come back as any. The following code snippet works in 4.15.0, but breaks in 4.16.0

Steps to Reproduce

import Fastify from "fastify";

const fastify = Fastify();

fastify.get(
  "/route",
  {
    onError: (request, reply, error) => {
      request // is any
      reply // is any
      error // is any
    },
  },
  async () => ({ success: "yes" })
);

The same appears to be true for all the other hooks specified in this manner as well.

Interestingly, hooks added with addHook appear to have the correct typings resolved

Expected Behavior

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bugtypescriptTypeScript related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions