Fix undefined error using getEffectiveTypeRoots (#19300)

This commit is contained in:
Andy 2017-10-18 15:47:15 -07:00 committed by Mohamed Hegazy
parent e5f8287e5c
commit f1abe3c284
2 changed files with 7 additions and 1 deletions

View file

@ -212,6 +212,11 @@ namespace Harness.LanguageService {
return script ? script.version.toString() : undefined;
}
directoryExists(dirName: string): boolean {
const fileEntry = this.virtualFileSystem.traversePath(dirName);
return fileEntry && fileEntry.isDirectory();
}
fileExists(fileName: string): boolean {
const script = this.getScriptSnapshot(fileName);
return script !== undefined;

View file

@ -367,7 +367,8 @@ namespace ts.codefix {
getCanonicalFileName: (file: string) => string,
moduleFileName: string,
): string | undefined {
return firstDefined(getEffectiveTypeRoots(options, host), unNormalizedTypeRoot => {
const roots = getEffectiveTypeRoots(options, host);
return roots && firstDefined(roots, unNormalizedTypeRoot => {
const typeRoot = toPath(unNormalizedTypeRoot, /*basePath*/ undefined, getCanonicalFileName);
if (startsWith(moduleFileName, typeRoot)) {
return removeExtensionAndIndexPostFix(moduleFileName.substring(typeRoot.length + 1));