microsoft / microsoft/TypeScript
importModuleSpecifier "shortest" does not choose shortest result among multiple matching paths aliases
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
言及されている tryGetModuleNameFromPaths エントリポイントから始め、jsconfig/tsconfig の paths 設定を使って複数ファイルの自動インポートのケースを再現します。一致するエイリアスがどのように選択されるかを追跡し、そのうえで、最短のものを優先することでオブジェクトキーの順序に依存せず短いエイリアスが選ばれることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- developer-experience, tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 52/100