From b31f2422234c91f1a242a45537f063f59ae9aa3a 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 d05d83505089a..7eea82a1fc018 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); }