Auto import from vscode suggestions fail if existing import path doesn't match TypeScript's preference. #46564
Labels
Bug
A bug in TypeScript
Crash
For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
Domain: Auto-import
Fix Available
A PR has been opened for this issue
Milestone
Bug Report
Auto imports within vscode suggestions fail if there's an existing valid import path, that doesn't appear to TypeScript's first preference as to where to import from. However, imports do still work via quick actions -> add to existing import declaration.
This appears to be coming from an assertion in the language server rather than from vscode behaviour.
🔎 Search Terms
vscode, auto, import, suggestions,
🕗 Version & Regression Information
⏯ Playground Link
Minimal reproduction repository
Linking to a repo instead of playground as it may involve usage of npm dependencies via file urls in package.json, not sure if workbench supports that.
Reproduction steps:
npm install
const a = new MyClass|();
const b = new MyClass2|();
If you change the version of typescript installed via npm to 4.3.5, reload the vscode window and follow the steps again, this seems to stop reproducing.
💻 Code
Not really applicable as it seems to be related to import functionality from language server.
🙁 Actual behavior
Auto completing while there is an existing an import that isn't TypeScript's first preference for where to import it, fails and nothing is imported.
🙂 Expected behavior
TypeScript should see that the target class can also be imported from the existing import, and add to it.
The text was updated successfully, but these errors were encountered: