microsoft / microsoft/TypeScript

importModuleSpecifier "shortest" does not choose shortest result among multiple matching paths aliases

オープン
#63,320 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

言及されている tryGetModuleNameFromPaths エントリポイントから始め、jsconfig/tsconfig の paths 設定を使って複数ファイルの自動インポートのケースを再現します。一致するエイリアスがどのように選択されるかを追跡し、そのうえで、最短のものを優先することでオブジェクトキーの順序に依存せず短いエイリアスが選ばれることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, typescript
領域
developer-experience, tooling
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。