Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prefer type correct import for add missing import for quick fixes

See original GitHub issue

Bug Report


🔎 Search Terms

  • Quick fix
  • auto import

🕗 Version & Regression Information

Tested version: 4.2.0-dev.20210201

⏯ Playground Link


💻 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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

mjbvzcommented, Feb 3, 2021

@RyanCavanaugh Yes, thinking about this more I agree this is probably not feasible for auto import suggestions right now.

For quick fixes though, the lightbulb generally should not produce invalid code so I think it does make sense to be smarter for those. Quick fixes are also being requested less often, so we don’t have the same performance concerns as with suggestions.

In VS Code, we also have an ‘auto fix’ command that will try to automatically apply the best quick fix to address a problem. It would be great if auto fix knew to use the type correct import by default instead of always defaulting to the first returned import suggestion

RyanCavanaughcommented, Feb 3, 2021

That distinction makes sense 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto-import quickfix : wrong strategy for import paths #15223
Actual behavior: With the new auto-import quick fix in TS2.2 (usable in VS Code), the suggested paths for missing imports are behaving strangely ......
Read more >
Auto import | IntelliJ IDEA Documentation - JetBrains
Basic procedures to create and optimize imports in IntelliJ IDEA. Learn more how to import the missing import or XML namespace.
Read more >
Visual Studio Code Automatic Imports - typescript
There are two types of auto imports: the add missing import quick fix which shows up as a lightbulb on errors: enter image...
Read more >
Working with JavaScript in Visual Studio Code
These type checks also enable some exciting Quick Fixes for JavaScript, including Add missing import and Add missing property. Using type checking and...
Read more >
Import or link to data in a text file - Microsoft Support
When you import fixed-width text files, Access does not give you the option of using the values in the first row as the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found