microsoft / microsoft/TypeScript

Improve behavior of typescript.preferences.importModuleSpecifier: non-relative

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

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

Awaiting More Feedback Domain: LS: Auto-import Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

⭐ Suggestion

Currently, with this setting"typescript.preferences.importModuleSpecifier": "non-relative" VScode goes to the tsconfig file and checks both baseUrl and paths and look for a match.

The situation that I experience is having a few paths in my path property and they sometimes overlap.
Example:

"baseUrl": ".",
    "paths": {
           "*": ["src/main/*"],
          "utilsFunctions/*": ["src/main/utils/utilsFunctions*"],
      },

With this configuration I can import a function from the utilsFunctions folder in one of these 2 options:

  1. import { foo } from "src/main/utils/utilsFunctions/functions.ts
  2. import { foo } from "utilsFunctions/functions.ts

Both of these import statements will work.

But If I add foo in my code without writing the import statement myself, vscode will auto-suggest me to use option no. 1, but In my case, I actually wanted option no.2 (in the above options).

Requested behavior:
When using foo (without it importing it first), VScode should suggest me both options.

My solution, in this case, was to reverse the order of paths like this:

    "paths": {
          "utilsFunctions/*": ["src/main/utils/utilsFunctions*"],
           "*": ["src/main/*"],
      },

🔍 Search Terms

importModuleSpecifier

✅ Viability Checklist

My suggestion meets these guidelines:

  • [ ✅ ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [ ✅ ] This wouldn't change the runtime behavior of existing JavaScript code
  • [ ✅ ] This could be implemented without emitting different JS based on the types of the expressions
  • [ ✅ ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [ ✅ ] This feature would agree with the rest of TypeScript's Design Goals.

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

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

はじめの一歩

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

調査の方向性

まず、typescript.preferences.importModuleSpecifier を non-relative に設定した、tsconfig baseUrl と paths が重複するケースを再現します。インポート候補がどのように選択されるかを追跡し、有効なモジュール指定子の両方をどのように提示すべきかを判断します。要求された代替候補が、既存のランタイム動作を変更せずに提案されれば完了です。

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

評価

技術スタック
typescript, vscode
領域
developer-experience, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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