Skip to content

Commit 8d4b4ff

Browse files
crisbetothePunderWoman
authored andcommitted
refactor(compiler-cli): work around internal test failure (#54327)
Fixes an internal test failure due to `FatalDiagnosticError` extending the native `Error`. PR Close #54327
1 parent 2e3fa28 commit 8d4b4ff

File tree

1 file changed

+5
-0
lines changed
  • packages/compiler-cli/src/ngtsc/diagnostics/src

1 file changed

+5
-0
lines changed

packages/compiler-cli/src/ngtsc/diagnostics/src/error.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export class FatalDiagnosticError extends Error {
1717
readonly diagnosticMessage: string|ts.DiagnosticMessageChain,
1818
readonly relatedInformation?: ts.DiagnosticRelatedInformation[]) {
1919
super(`FatalDiagnosticError #${code}: ${diagnosticMessage}`);
20+
21+
// Extending `Error` ends up breaking some internal tests. This appears to be a known issue
22+
// when extending errors in TS and the workaround is to explicitly set the prototype.
23+
// https://stackoverflow.com/questions/41102060/typescript-extending-error-class
24+
Object.setPrototypeOf(this, new.target.prototype);
2025
}
2126

2227
// Trying to hide `.message` from `Error` to encourage users to look

0 commit comments

Comments
 (0)