diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index c17dfeabcf1..db0b49f4436 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -854,8 +854,8 @@ namespace ts.moduleSpecifiers { function getPathRelativeToRootDirs(path: string, rootDirs: readonly string[], getCanonicalFileName: GetCanonicalFileName): string | undefined { return firstDefined(rootDirs, rootDir => { - const relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName)!; // TODO: GH#18217 - return isPathRelativeToParent(relativePath) ? undefined : relativePath; + const relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName); + return relativePath !== undefined && isPathRelativeToParent(relativePath) ? undefined : relativePath; }); } diff --git a/tests/cases/fourslash/autoImportsWithRootDirsAndRootedPath01.ts b/tests/cases/fourslash/autoImportsWithRootDirsAndRootedPath01.ts new file mode 100644 index 00000000000..08073349cb1 --- /dev/null +++ b/tests/cases/fourslash/autoImportsWithRootDirsAndRootedPath01.ts @@ -0,0 +1,24 @@ +/// + +// @Filename: /dir/foo.ts +//// export function foo() {} + +// @Filename: /dir/bar.ts +//// /*$*/ + +// @Filename: /dir/tsconfig.json +////{ +//// "compilerOptions": { +//// "module": "amd", +//// "moduleResolution": "classic", +//// "rootDirs": ["D:/"] +//// } +////} + +goTo.marker("$"); +verify.completions({ + preferences: { + includeCompletionsForModuleExports: true, + allowIncompleteCompletions: true, + } +});