microsoft / microsoft/TypeScript

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

Aperta
#38,325 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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:

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia confrontando i repository della versione con bug e della versione corretta collegati nell’issue, usando la configurazione AMD/System con outFile e i riferimenti circolari ai namespace su più file. Traccia la risoluzione delle dipendenze del compilatore e la gestione dei commenti di riferimento, quindi verifica che il comportamento scelto compili e venga eseguito correttamente per il progetto mostrato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.