0
I’m creating a class of ErrorHandler
for an API. When creating variables in the class constructor, Typescript accuses that variable statusCode
does not have a defined type:
interface ErrorObj {
statusCode: number;
message: string;
}
class ErrorHandler extends Error {
constructor({ statusCode, message }: ErrorObj) {
super();
this.statusCode = statusCode; // variável que o TypeScript acusa erro de tipo
this.message = message;
}
}
I get this mistake:
Property 'statusCode' does not exist on type 'ErrorHandler'. ts(2339)
This typing would not come from the interface?
Hello Matheus, although the answer of Luiz explain well where the fault was, I closed the question because it is a simple error of use/ typing (I do not speak of parser error) that really is very occasional to occur and if translate the "error message" would help to understand the problem easily. More details: https://answall.com/help/on-topic - Thank you for understanding, and welcome to the website.
– Guilherme Nascimento