-
-
Notifications
You must be signed in to change notification settings - Fork 20
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 type of base argument create error #108
Fix type of base argument create error #108
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use ErrorConstructor
if you really means to be a constructor.
I'd like to be able to use this with classes that inherit from Error, which aren't callable as functions like |
I'm having difficulty following the reasoning for this PR, but it sounds like a misunderstanding of https://262.ecma-international.org/13.0/#sec-error-objects
|
@jsumners The value The current types defined for This PR makes it possible to call Without this change it's not possible to call createError() correctly from Typescript. |
ping: @fastify/typescript |
interface ErrorConstructor {
new(message?: string): Error;
(message?: string): Error;
readonly prototype: Error;
} But, I still in favor of using |
As @Uzlopak said, this is a TS definition issue. Thanks for finding and fixing it, @jessta! |
4372c10
to
0c544c4
Compare
I've updated the types to be ErrorConstructor since that seems to be the consensus. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR fixes the type of the Base argument to createError.
The previous type was Error which is the type of an Error value, but it's being used is as a constructor for a class that inherits from Error.
This change makes the type of Base a constructor for a class that inherits from Error so it's type matches it's usage and documented examples.
Checklist
npm run test
andnpm run benchmark
and the Code of conduct