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

Fix inaccurate type of setErrorHandler #2092

Merged
merged 3 commits into from Feb 13, 2020
Merged

Fix inaccurate type of setErrorHandler #2092

merged 3 commits into from Feb 13, 2020

Conversation

chengluyu
Copy link
Contributor

@chengluyu chengluyu commented Feb 12, 2020

See #2091

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

Copy link

@tests-checker tests-checker bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thank you for contributing!
It appears that you have changed the framework code, but the tests that verify your change are missing. Could you please add them?

@Ethan-Arrowood
Copy link
Member

This should not be any. I'd rather you make this unknown and instruct the user to use type casting to enforce what they want to come through this handler. Based on the code you provided in your issue, throw {hello: 'world'} will result in a type of { hello: string }. If you captured that in a type i.e. type CustomError = { hello: string }, then the goal would be to use use that type in setErrorHandler. You can achieve this through generics or type casting. I'd suggest supporting both by using a default generic, so something like this:

setErrorHandler<E = FastifyError>(error: E, ...)

@chengluyu
Copy link
Contributor Author

chengluyu commented Feb 13, 2020

This should not be any. I'd rather you make this unknown and instruct the user to use type casting to enforce what they want to come through this handler. Based on the code you provided in your issue, throw {hello: 'world'} will result in a type of { hello: string }. If you captured that in a type i.e. type CustomError = { hello: string }, then the goal would be to use use that type in setErrorHandler. You can achieve this through generics or type casting. I'd suggest supporting both by using a default generic, so something like this:

setErrorHandler<E = FastifyError>(error: E, ...)

I agree with you. I've replaced any with generic type parameter (defaults to FastifyError). Therefore, users can specify their own error types.

@mcollina
Copy link
Member

Can you add a test for the type change?

@chengluyu
Copy link
Contributor Author

Can you add a test for the type change?

Hi, I've added a test. Please let me know if there's any problem. 😄

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
typescript TypeScript related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants