From 07da12167edafb9927efaf64d5541408e2c1b1c4 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 20 Jul 2018 12:20:39 -0700 Subject: [PATCH] Reflect getCurrentProgram as Program|undefined in the ResolutionHostCache If there were any exceptions, the getCurrentProgram might return undefined so this is defensive check for program Fixes #25765 --- src/compiler/resolutionCache.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index d05d8350508..7eea82a1fc0 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -52,7 +52,7 @@ namespace ts { getGlobalCache?(): string | undefined; writeLog(s: string): void; maxNumberOfFilesToIterateForInvalidation?: number; - getCurrentProgram(): Program; + getCurrentProgram(): Program | undefined; } interface DirectoryWatchesOfFailedLookup { @@ -497,7 +497,8 @@ namespace ts { } function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions: ResolutionWithFailedLookupLocations[], name: string) { - const updateResolution = resolutionHost.getCurrentProgram().getTypeChecker().tryFindAmbientModuleWithoutAugmentations(name) ? + const program = resolutionHost.getCurrentProgram(); + const updateResolution = program && program.getTypeChecker().tryFindAmbientModuleWithoutAugmentations(name) ? setRefCountToUndefined : watchFailedLookupLocationOfResolution; resolutions.forEach(updateResolution); }