microsoft / microsoft/TypeScript

Add a specific error message for disallowed imports in project references?

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

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

Needs Proposal Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Suggestion

🔍 Search Terms

project reference back import

✅ 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.

⭐ Suggestion

After introducing project references to a monolith repo with many developers, I've sometimes seen confusion over people writing imports from projects in the incorrect direction: e.g. if project B has a tsconfig reference to project A, trying to import from B in A. ♻️

https://github.com/JoshuaKGoldberg/ts-repro-back-reference-import

Here's an example error message that says what's technically wrong but doesn't give much context:

src/a/index.ts:1:19 - error TS6307: File '---/src/b/index.ts' is not listed within the file list of project '---/src/a/tsconfig.json'. Projects must list all files or use an 'include' pattern.

1 import { b } from "../b";
                    ~~~~~~

📃 Motivating Example

Adding a specific error for these incorrect direction ("back") imports might help folks new to project references understand what they're doing wrong:

src/a/index.ts:1:19 - error TS6307: File '---/src/b/index.ts' is not listed within the file list of project '---/src/a/tsconfig.json'. Projects must list all files or use an 'include' pattern.

  File "---/b/index.ts" is included in "---/b/tsconfig.json", but "---/a/tsconfig.json" does not list a reference to "---/b/tsconfig.json".

1 import { b } from "../b";
                    ~~~~~~

💻 Use Cases

https://github.com/JoshuaKGoldberg/ts-repro-back-reference-import

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

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

はじめの一歩

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

調査の方向性

リンク先の ts-repro-back-reference-import リポジトリで back-reference import を再現することから始め、関係する tsconfig.json のプロジェクト参照を調べます。既存の TS6307 診断を提案された追加コンテキストと比較し、その後、プロジェクトファイルの包含を処理している TypeScript コンパイラの診断およびテストの場所を特定します。不正な import が具体的で対応可能なメッセージを生成し、有効なプロジェクト参照の動作を変更しない状態になれば完了です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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