microsoft / microsoft/TypeScript
Prefer type correct import for add missing import for quick fixes
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
From https://github.com/microsoft/vscode/issues/115370
🔎 Search Terms
- Quick fix
- auto import
🕗 Version & Regression Information
Tested version: 4.2.0-dev.20210201
⏯ Playground Link
N/A
💻 Code
For the project:
// a1.ts
export const abc = 123
// a2.ts
export const abc = '123'
// index.ts
function foo(x: string) { }
foo(abc); // trigger quick fix here
- Trigger the quick fix on
abcinfoo(abc)
🙁 Actual behavior
The import quick fixes are returned in file order:
Accepting the first suggestion results in invalid code:
🙂 Expected behavior
In this case, we should sort the import for a2 before a1 since it has the correct type
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the quick fix in index.ts using the a1.ts and a2.ts examples, then trace the auto-import quick-fix ranking from the abc reference in foo(abc). Verify that the candidate exporting the type-compatible value is ordered first, and add or update coverage for this case if the relevant quick-fix tests are found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100