Fix type of base argument create error#108
Conversation
climba03003
left a comment
There was a problem hiding this comment.
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. |

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 testandnpm run benchmarkand the Code of conduct