From d8ce7d72a92cc76ee3e6be57136439d3d980acd2 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 25 Feb 2020 11:09:32 -0800 Subject: [PATCH] Check for undefined `source.symbol` Fixes #37014 --- src/compiler/checker.ts | 1 + tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a1a0b598231b7..b92c95b14d12c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16239,6 +16239,7 @@ namespace ts { if (unmatchedProperty.valueDeclaration && isNamedDeclaration(unmatchedProperty.valueDeclaration) && isPrivateIdentifier(unmatchedProperty.valueDeclaration.name) + && source.symbol && source.symbol.flags & SymbolFlags.Class) { const privateIdentifierDescription = unmatchedProperty.valueDeclaration.name.escapedText; const symbolTableKey = getSymbolNameForPrivateIdentifier(source.symbol, privateIdentifierDescription); diff --git a/tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts b/tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts new file mode 100644 index 0000000000000..09f8cf460ed29 --- /dev/null +++ b/tests/cases/compiler/privateFieldAssignabilityFromUnknown.ts @@ -0,0 +1,5 @@ +export class Class { + #field: any +} + +const task: Class = {} as unknown;