Bug Report
The system Error class cannot be extended without calling Object.setPrototypeOf() as a workaround, like this:
class FooError extends Error {
constructor(m: string) {
super(m);
// Set the prototype explicitly.
Object.setPrototypeOf(this, FooError.prototype);
}
}
The TypeScript 2.1 release notes imply that this behavior is by design.
However when I proposed to implement this workaround in the ANTLR4 runtime library, they observed that Babel injects the workaround automatically. Thus they concluded that this is a TypeScript bug rather than a problem with their library.
Is there some reason why TypeScript's transpiler cannot use the same solution as Babel?
🔎 Search Terms
setPrototypeOf extends Error
🕗 Version & Regression Information
Repros in TypeScript 4.1.3, first introduced in TypeScript 2.1.0
Bug Report
The system
Errorclass cannot be extended without callingObject.setPrototypeOf()as a workaround, like this:The TypeScript 2.1 release notes imply that this behavior is by design.
However when I proposed to implement this workaround in the ANTLR4 runtime library, they observed that Babel injects the workaround automatically. Thus they concluded that this is a TypeScript bug rather than a problem with their library.
Is there some reason why TypeScript's transpiler cannot use the same solution as Babel?
🔎 Search Terms
setPrototypeOf extends Error
🕗 Version & Regression Information
Repros in TypeScript 4.1.3, first introduced in TypeScript 2.1.0