I'm trying to enhance the standard JavaScript Error
class by adding another property called code
, but for some reason, TypeScript is not allowing me to do so. Here is the code snippet:
export class HttpError extends Error {
public message: string
public errorCode: number
constructor(message: string, errorCode: number) {
super(message)
(this as any).code = errorCode
}
}
The error occurs at the super(message)
line and it says:
This expression is not callable.
Type 'void' has no call signatures.ts(2349)
Interestingly, I found in the TypeScript documentation that a similar approach is used: https://www.typescriptlang.org/docs/handbook/classes.html
Can anyone spot what might be wrong with my code?