I want to create my own error class that extends the base JS Error class and has mutliple getters defined.
example:
class CustomError extends Error {
public get code(): string {
return "my-code";
}
}
const myError = new CustomError("uuu");
console.log("message", myError.message); // the message "uuu"
console.log("code", myError.code); // undefined
The problem is that if I want to get the getter value I get undefined in return and not the desired value.
Does anybody know why this is how it is or what I am doing wrong?
Thanks!
edit: my tsconfig.json
:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["dom","es6", "es2016"],
"declaration": true,
"outDir": "dist",
"rootDir": "src",
"removeComments": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
},
"exclude": [ "node_modules" ],
"include": [ "src/**/*.ts" ]
}
see repl.it: https://repl.it/repls/DentalVoluminousPerformance