Closed
Description
TypeScript Version: 4.0.3
Search Terms: auto imports
Code
Reduced test case: https://github.com/OliverJAsh/ts-project-references-playground/tree/imports-bug. Below I have inlined the code from this repository.
shared/tsconfig.json
:
{
"compilerOptions": {
"composite": true,
"outDir": "../target-tsc-build/",
"rootDir": ".."
},
"files": ["./main.ts"]
}
shared/main.ts
:
export const shared = 1;
webpack/tsconfig.json
:
{
"compilerOptions": {
"outDir": "../target-tsc-build/",
"rootDir": "..",
"baseUrl": "./",
"paths": {
"shared/*": ["../shared/*"]
}
},
"files": ["a.ts", "b.ts"],
"references": [
{
"path": "../shared/tsconfig.json"
}
]
}
webpack/a.ts
:
import { shared } from "shared/main";
console.log(shared);
webpack/b.ts
:
console.log(shared);
Expected behavior:
When I open webpack/b.ts
- TypeScript should suggest importing symbol
shared
fromshared/main
. There should be no other suggestions. - Activating auto import should result in:
import { shared } from "shared/index"; console.log(shared);
Actual behavior:
- TypeScript suggests importing symbol
shared
from../target-tsc-build/shared/main
(the file inoutDir
) and thenshared/main
.
- Activating auto import results in:
The
import { shared } from "../target-tsc-build/shared/main"; console.log(shared);
outDir
file is the primary suggestion, therefore it is used for auto import:
Import suggestions should never be provided for compiled files—only source files.
Note I also tried adding exclude: ["./target-tsc-build/"]
and "declarationMaps": true
to all configs, but that didn't seem to help.
Playground Link:
Related Issues: