Skip to content

Commit f1abe3c

Browse files
Andymhegazy
Andy
authored andcommitted
Fix undefined error using getEffectiveTypeRoots (#19300)
1 parent e5f8287 commit f1abe3c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/harness/harnessLanguageService.ts

+5
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ namespace Harness.LanguageService {
212212
return script ? script.version.toString() : undefined;
213213
}
214214

215+
directoryExists(dirName: string): boolean {
216+
const fileEntry = this.virtualFileSystem.traversePath(dirName);
217+
return fileEntry && fileEntry.isDirectory();
218+
}
219+
215220
fileExists(fileName: string): boolean {
216221
const script = this.getScriptSnapshot(fileName);
217222
return script !== undefined;

src/services/codefixes/importFixes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ namespace ts.codefix {
367367
getCanonicalFileName: (file: string) => string,
368368
moduleFileName: string,
369369
): string | undefined {
370-
return firstDefined(getEffectiveTypeRoots(options, host), unNormalizedTypeRoot => {
370+
const roots = getEffectiveTypeRoots(options, host);
371+
return roots && firstDefined(roots, unNormalizedTypeRoot => {
371372
const typeRoot = toPath(unNormalizedTypeRoot, /*basePath*/ undefined, getCanonicalFileName);
372373
if (startsWith(moduleFileName, typeRoot)) {
373374
return removeExtensionAndIndexPostFix(moduleFileName.substring(typeRoot.length + 1));

0 commit comments

Comments
 (0)