You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should prefer relative path first before index when it comes to suggestions #47040
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:
Have a function that is exported from a file, call it './baseSchemas.ts'
Have an index file that exports the contents of that file, export * as baseSchemas from './baseSchemas'
Try to import that function in a file, see something like this:
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.
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).
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
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).
Reacted by William Lahti and Boris Okunskiy
Reacted by m.e., William Lahti and Václav Jančařík
Activity
RyanCavanaugh commentedon Dec 7, 2021
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 commentedon Dec 7, 2021
Ryan Cavanaugh (@RyanCavanaugh) makes sense. Is there a way to switch the order? I had seen an
TypeScript › Preferences: Import Module Specifierbut not sure if that influences thisRyanCavanaugh commentedon Dec 7, 2021
Not sure. Andrew Branch (@andrewbranch) ?
andrewbranch commentedon Dec 7, 2021
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).
typescript-bot commentedon Dec 10, 2021
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.