Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete won't choose shortest absolute import path for subfolders or sibling folders - even though Quick Fix works fine. #44544

Closed
dalmo3 opened this issue Jun 11, 2021 · 2 comments
Assignees
Labels
Duplicate An existing issue was already created

Comments

@dalmo3
Copy link

dalmo3 commented Jun 11, 2021

Bug Report

In a project structured like this:

.
|- index.tsx
|- components
|  |- index.ts
|  |- A
|     |- index.tsx
|  |- B
|     |- index.tsx

Where baseUrl: "." and index.ts files are written in way to export modules up the tree:

--  components/index.ts --

export * from './A'
export * from './B'

When editing any files under components or its subfolders, if you try to import component A using tab to autocomplete, intellisense will automatically add an import from components/A instead of from just components.

Auto importing with quick fix Ctrl+. works as expected. The gif below demonstrates both tabbing and using quick fix.

1
See, quick fix gets the sorting right, and in case the first choice is already imported it even hides the other options which is fine.

In VSCode, that happens regardless of selecting Import Module Specifier as shortest or non-relative. (Though shortest sometimes results in relative paths).

I haven't seen the problem happen in files not under components. It works as expected.

🔎 Search Terms

Autocomplete, auto import, intellisense, import module specifier

🕗 Version & Regression Information

TS 4.2.2 and up

⏯ Playground Link

Fully reproducible here: https://codesandbox.io/s/hidden-lake-9jfk3?file=/src/components/A/index.tsx

🙂 Expected behavior

Autocomplete on tab should import module with the shortest possible path, just like quick fix, especially if selected non-relative as the specifier.

@andrewbranch
Copy link
Member

Duplicate of #41083

@andrewbranch andrewbranch marked this as a duplicate of #41083 Jun 15, 2021
@andrewbranch andrewbranch added Duplicate An existing issue was already created and removed Bug A bug in TypeScript Domain: Auto-import labels Jun 15, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants