microsoft / microsoft/TypeScript
importModuleSpecifier "shortest" does not choose shortest result among multiple matching paths aliases
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
🔎 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
Start at the mentioned tryGetModuleNameFromPaths entry point and reproduce the multi-file auto-import case using the jsconfig/tsconfig paths configuration. Trace how matching aliases are selected, then verify that the shortest preference produces the shorter alias rather than depending on object key order.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- developer-experience, tooling
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 52/100