From 9256e119c660e3de267d7b8a5352bc10d9a1d575 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 17 Dec 2021 15:45:27 -0800 Subject: [PATCH 1/2] Check for undefined globalObjectType in getPropertyOfObjectType This can happen during symbol merging when initialising the checker, because global types aren't set until after symbols are merged. May stop the crashes in #47179, #47181, #47180. Does not address the underlying problem of needing to resolve aliases, and therefore names, during symbol merging when initialising the checker. --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ae7b16234fead..d5a52db2a6299 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12360,7 +12360,7 @@ namespace ts { return symbol; } } - return getPropertyOfObjectType(globalObjectType, name); + return globalObjectType === undefined ? undefined : getPropertyOfObjectType(globalObjectType, name); } if (type.flags & TypeFlags.UnionOrIntersection) { return getPropertyOfUnionOrIntersectionType(type as UnionOrIntersectionType, name, skipObjectFunctionPropertyAugment); From c71e781443ddb40f0811545e3309aa09523b8c99 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 20 Dec 2021 12:45:37 -0800 Subject: [PATCH 2/2] Add comment, switch to &&. --- src/compiler/checker.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d5a52db2a6299..2f43eead70361 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12360,7 +12360,9 @@ namespace ts { return symbol; } } - return globalObjectType === undefined ? undefined : getPropertyOfObjectType(globalObjectType, name); + // TODO: In some cases, the containing function may be called before global types have been initialized. + // This simple guard avoids issues with those cases, but in the future we may need to reconsider how these steps are ordered. + return globalObjectType && getPropertyOfObjectType(globalObjectType, name); } if (type.flags & TypeFlags.UnionOrIntersection) { return getPropertyOfUnionOrIntersectionType(type as UnionOrIntersectionType, name, skipObjectFunctionPropertyAugment);