Skip to content

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

Closed

Description

@mmahalwy

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.

Activity

  1. removed their assignment
    on Dec 6, 2021
  2. RyanCavanaugh commented on Dec 7, 2021

    @RyanCavanaugh
    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).

  3. mmahalwy commented on Dec 7, 2021

    @mmahalwy
    Author

    Ryan Cavanaugh (@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

  4. RyanCavanaugh commented on Dec 7, 2021

    @RyanCavanaugh
    Member
  5. andrewbranch commented on Dec 7, 2021

    @andrewbranch
    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).

  6. added
    DuplicateAn existing issue was already created
    and removed
    Working as IntendedThe behavior described is the intended behavior; this is not a bug
    on Dec 7, 2021
  7. typescript-bot commented on Dec 10, 2021

    @typescript-bot
    Contributor

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

  8. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions