Skip to content

Commit 721bc72

Browse files
crisbetothePunderWoman
authored andcommittedMay 25, 2023
fix(compiler): resolve deprecation warning with TypeScript 5.1 (#50460)
We have a code path that accesses the `originalKeywordKind` property which logs a deprecation warning in version 5.1, but isn't available in some of the earlier versions that we support. These changes add a compatibility layer that goes through the non-deprecated function, if it exists. PR Close #50460
1 parent 258c773 commit 721bc72

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
 

‎packages/compiler-cli/src/ngtsc/partial_evaluator/src/interpreter.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export class StaticInterpreter {
216216
private visitIdentifier(node: ts.Identifier, context: Context): ResolvedValue {
217217
const decl = this.host.getDeclarationOfIdentifier(node);
218218
if (decl === null) {
219-
if (node.originalKeywordKind === ts.SyntaxKind.UndefinedKeyword) {
219+
if (getOriginalKeywordKind(node) === ts.SyntaxKind.UndefinedKeyword) {
220220
return undefined;
221221
} else {
222222
// Check if the symbol here is imported.
@@ -763,3 +763,14 @@ function owningModule(context: Context, override: OwningModule|null = null): Own
763763
return null;
764764
}
765765
}
766+
767+
/**
768+
* Gets the original keyword kind of an identifier. This is a compatibility
769+
* layer while we need to support TypeScript versions less than 5.1
770+
* TODO(crisbeto): remove this function once support for TS 4.9 is removed.
771+
*/
772+
function getOriginalKeywordKind(identifier: ts.Identifier): ts.SyntaxKind|undefined {
773+
return typeof (ts as any).identifierToKeywordKind === 'function' ?
774+
(ts as any).identifierToKeywordKind(identifier) :
775+
identifier.originalKeywordKind;
776+
}

0 commit comments

Comments
 (0)
Please sign in to comment.