I want to simply extend the standard javascript Error
class. I want to add another property: code
, but somehow, the typescript don't let me do it.
export class HttpError extends Error {
public message: string
public errorCode: number
constructor(message: string, errorCode: number) {
super(message) // Add a
(this as any).code = errorCode
}
}
The typescript error is at the super(message)
:
This expression is not callable.
Type 'void' has no call signatures.ts(2349)
However, in typescript documentation: https://www.typescriptlang.org/docs/handbook/classes.html they also do the same way.
What's wrong with my code?