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

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

Closed
2 tasks done
vidarc opened this issue Apr 26, 2023 · 6 comments
Closed
2 tasks done
Labels
bug Confirmed bug typescript TypeScript related

Comments

@vidarc
Copy link
Contributor

vidarc commented Apr 26, 2023

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

@Eomm Eomm added bug Confirmed bug typescript TypeScript related labels Apr 26, 2023
@Eomm
Copy link
Member

Eomm commented Apr 26, 2023

Thanks for reporting!
Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@mcollina
Copy link
Member

Can you please include a script that compiles in v4.15.0 and it does not in v4.16.0. That would help in bisecting the problem.

@vidarc
Copy link
Contributor Author

vidarc commented Apr 26, 2023

Do you need something more than the attached code snippet? That shows the problem between the 2 versions

@vidarc
Copy link
Contributor Author

vidarc commented Apr 26, 2023

It's definitely due to #4655

If I take the types/route.d.ts file from before that PR was merged, the types work as expected

@mcollina
Copy link
Member

Anything that I can quickly run in a bash shell that returns 1 if it fails. Opening an editor and trying to autocomplete is not great for git bisecting.

@Fdawgs
Copy link
Member

Fdawgs commented Apr 27, 2023

closed by #4708

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

No branches or pull requests

4 participants