Skip to content

Should prefer relative path first before index when it comes to suggestions #47040

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

Closed
mmahalwy opened this issue Dec 2, 2021 · 5 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@mmahalwy
Copy link

mmahalwy commented Dec 2, 2021

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.62.3
  • OS Version: Darwin arm64 20.6.0

Steps to Reproduce:

  1. Have a function that is exported from a file, call it './baseSchemas.ts'
  2. Have an index file that exports the contents of that file, export * as baseSchemas from './baseSchemas'
  3. Try to import that function in a file, see something like this:
    image

Expectation is the relative should be preferred over the index. When importing or default to index, it can cause a circular dependency if index is imported, which then index imports the same file.

@mjbvz mjbvz transferred this issue from microsoft/vscode Dec 6, 2021
@mjbvz mjbvz removed their assignment Dec 6, 2021
@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 7, 2021
@RyanCavanaugh
Copy link
Member

This is the intended behavior; shorter paths (those with fewer directory separators) are always preferred over longer ones. The motivation is that packages which re-export their contents are typically doing so to provide a unified API surface (meaning they don't want you to index into their subdirectories as shown here).

@mmahalwy
Copy link
Author

mmahalwy commented Dec 7, 2021

@RyanCavanaugh makes sense. Is there a way to switch the order? I had seen an TypeScript › Preferences: Import Module Specifier but not sure if that influences this

@RyanCavanaugh
Copy link
Member

Not sure. @andrewbranch ?

@andrewbranch
Copy link
Member

Duplicate of #45953. We’ll probably drop paths that resolve to nothing but dots and slashes as that often creates an import cycle between a barrel re-export and the file that’s importing it (which may not be a problem at runtime, but can be if the modules have side effects, and I’ve just never seen anyone use import paths like that on purpose).

@andrewbranch andrewbranch added Duplicate An existing issue was already created and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Dec 7, 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

5 participants