microsoft / microsoft/TypeScript

Prefer type correct import for add missing import for quick fixes

Open
#42,615 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
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
  1. Trigger the quick fix on abc in foo(abc)
🙁 Actual behavior

The import quick fixes are returned in file order:

Screen Shot 2021-02-02 at 12 45 53 PM

Accepting the first suggestion results in invalid code:

Screen Shot 2021-02-02 at 12 46 42 PM
🙂 Expected behavior

In this case, we should sort the import for a2 before a1 since it has the correct type

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.