microsoft / microsoft/TypeScript

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

Offen
#43,253 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Needs Proposal Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den Back-Reference-Import im verlinkten Repository ts-repro-back-reference-import zu reproduzieren, und untersuche die beteiligten Projektverweise in tsconfig.json. Vergleiche die vorhandene TS6307-Diagnose mit dem vorgeschlagenen zusätzlichen Kontext und ermittle anschließend die Stellen in der TypeScript-Compiler-Diagnose und den Tests, die die Einbindung von Projektdateien behandeln. Als erledigt gilt die Aufgabe, wenn der inkorrekte Import eine spezifische, umsetzbare Meldung erzeugt, ohne das Verhalten gültiger Projektverweise zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.