🔎 Search Terms
importModuleSpecifier shortest paths multiple aliases, auto import paths overlapping alias, tryGetModuleNameFromPaths shortest
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about auto-import and paths
⏯ Playground Link
N/A — this is a language service auto-import behavior that requires a multi-file project with jsconfig/tsconfig paths
💻 Code
// jsconfig.json
{
"compilerOptions": {
"paths": {
"@@/*": ["./*"],
"@/*": ["./src/*"]
}
}
}
// src/services/foo.js
export function foo() {}
// src/index.js — trigger auto-import for `foo`
🙁 Actual behavior
Auto-import suggests @@/src/services/foo. The importModuleSpecifier: "shortest" preference does not influence the choice between two matching paths aliases. tryGetModuleNameFromPaths returns on the first matching key in iteration order without comparing alternatives.
🙂 Expected behavior
With importModuleSpecifier set to "shortest", auto-import should compare all matching aliases and suggest @/services/foo since it is shorter than @@/src/services/foo.
Additional information about the issue
Workaround is to reorder paths entries so the more specific alias appears first, relying on object key insertion order. This is fragile and undocumented.
🔎 Search Terms
importModuleSpecifier shortest paths multiple aliases, auto import paths overlapping alias, tryGetModuleNameFromPaths shortest
🕗 Version & Regression Information
⏯ Playground Link
N/A — this is a language service auto-import behavior that requires a multi-file project with jsconfig/tsconfig
paths💻 Code
🙁 Actual behavior
Auto-import suggests
@@/src/services/foo. TheimportModuleSpecifier: "shortest"preference does not influence the choice between two matchingpathsaliases.tryGetModuleNameFromPathsreturns on the first matching key in iteration order without comparing alternatives.🙂 Expected behavior
With
importModuleSpecifierset to"shortest", auto-import should compare all matching aliases and suggest@/services/foosince it is shorter than@@/src/services/foo.Additional information about the issue
Workaround is to reorder
pathsentries so the more specific alias appears first, relying on object key insertion order. This is fragile and undocumented.