Due to compatibility issues with Internet Explorer, I find myself needing to create a custom Error that must be validated using the constructor.
customError instanceof CustomError; // false
customError.constructor === CustomError; // true
But how can I make TypeScript understand this in an if statement?
if (customError.constructor === CustomError) {
customError.customMethod1() // typescript complaints
customError.customMethod2() // typescript complaints
customError.customMethod3() // typescript complaints
customError.customMethod4() // typescript complaints
}
UPDATE:
The issue arises when transpiling to ES5, causing conflicts with some inheritances.
Is there a way to cast it once and avoid using as
every time the variable is used?
Currently, the workaround is as follows:
const myCustomError = (customError as CustomError)
Open to any creative suggestions.