I have a custom Error404 class and a function run to which I want to pass this error constructor:
class Error404 extends Error {
constructor(message: string) {
super(message);
this.name = "404";
this.message = message;
}
}
function run(MyErr: ErrorConstructor) {
throw new MyErr("test");
}
But when trying to invoke it I get:
run(Error404)
^^^^^^^^
class Error404
Argument of type 'typeof Error404' is not assignable to parameter of type 'ErrorConstructor'.
Type 'typeof Error404' provides no match for the signature '(message?: string): Error'.ts(2345)
What am I doing wrong? How to fix it?