Is there a way to properly extend the Error
class in TypeScript version 3.3 and have it work correctly with the instanceof
operator?
class CustomError extends Error {
constructor(
message: string,
public readonly description: string
) { super(message) }
}
try {
throw new CustomError('error message', 'error details')
} catch (err) {
console.log(err.message) // Output is correct
console.log(err.description) // Output is correct
console.log(err instanceof CustomError) // This should be true, but it prints false
}