microsoft / microsoft/TypeScript

Automatic multi-file namespace references in AMD/System modules are buggy in complicated situations

Offen
#38,325 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Needs Investigation
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

TypeScript Version: 3.8.3

Search Terms: AMD, System, Reference, Circular reference, Automatic Reference, Auto Reference, Multi-file Namespace, Splitting Across Files

Problem

While most people use TypeScript with a commonjs way of modeling. There are a fraction of this community that uses the AMD / System setup—just like the TypeScript compiler itself—and a common practice is to have outFile enabled. In this situation the compiler automatically detects which file is the dependency of what other file and arranges the namespaces in such way that it can be put into a single file.

This however is not when it comes to rather complicated structures in which one has namespaces separated in multiple files and have circular referencing in them. For that TypeScript does have these /// <reference path="..." /> comments that act like the require / import features.

Using the reference comments always solves any kind of dependency resolution. But the problem is while the compiler halts on using an identifier without importing on other modules (import / require), there is no compiler error or even warning on not using the reference comments.

I do not know what is the bug in here:

  • Is it that the compiler gives no error on absence of the reference comment?
  • Or is the file dependency graph resolver that is buggy?

I have demonstrated a situation in which a simple project with a complicated enough graph of dependencies show how the problem can be replicated. This is the graph describing the structure of this project and a git repository containing both a working version and a buggy version is provided respectively:

Code

Expected behavior:

  • I think either the compiler should have the right dependency resolver and insert reference tags for all the calls to other files in each file.
  • Or the reference comments should be forced on all files and the compiler gives errors that one identifier cannot be found because it is not resolved with the reference comment.

Actual behavior:

If you use the reference comments for all the imported identifiers in every file the code will run successfully but if you remove them it will compile but the code will not work because it has type checking problems on undefined modules. This screenshot shows the working and buggy versions for good:

Playground Link:

Related Issues:

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

Beginnen Sie damit, die im Issue verlinkten Repositories der fehlerhaften und der korrigierten Version zu vergleichen, und verwenden Sie dabei die AMD/System-Konfiguration mit outFile sowie die zirkulären Namespace-Referenzen über mehrere Dateien hinweg. Verfolgen Sie die Abhängigkeitsauflösung des Compilers und die Verarbeitung von Referenzkommentaren und überprüfen Sie anschließend, dass das gewählte Verhalten für das demonstrierte Projekt korrekt kompiliert und ausgeführt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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