Skip to content

Commit 47212e0

Browse files
devversionAndrewKushnir
authored andcommitted
refactor(compiler-cli): fix instanceof for error not working (angular#59219)
We recently introduced a custom error to allow us to catch certain types of errors. Unfortunately it doesn't work as expected in G3 because the Node execution seems to run with ES5. PR Close angular#59219
1 parent 204d109 commit 47212e0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/compiler-cli/src/ngtsc/reflection/src/typescript.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,16 @@ export function reflectIdentifierOfDeclaration(decl: ts.Declaration): ts.Identif
533533
return null;
534534
}
535535

536-
export class TypeEntityToDeclarationError extends Error {}
536+
export class TypeEntityToDeclarationError extends Error {
537+
constructor(message: string) {
538+
super(message);
539+
540+
// Extending `Error` ends up breaking some internal tests. This appears to be a known issue
541+
// when extending errors in TS and the workaround is to explicitly set the prototype.
542+
// https://stackoverflow.com/questions/41102060/typescript-extending-error-class
543+
Object.setPrototypeOf(this, new.target.prototype);
544+
}
545+
}
537546

538547
/**
539548
* @throws {TypeEntityToDeclarationError} if the type cannot be converted

0 commit comments

Comments
 (0)