microsoft / microsoft/TypeScript
Incorrect error message on export assignment in `.d.ts` file
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: 3.5.3
Search Terms:
An export assignment cannot be used in a namespace.
Code
This is pretty niche, but I think it has general implications...
The current /lib/typescript.d.ts file is modelled as essentially a CommonJS file where at the end of the file, it has export = ts; which exports the whole namespace. The actual /lib/typescript.js though will place itself in the global scope as ts if it isn't loaded as a CommonJS module. In order to express that ts is available as a global variable, it requires code like this to be placed in a .d.ts file:
import * as _ts from "typescript";
declare global {
namespace ts {
export = _ts;
}
}
Other methods of expressing this, like declare var ts: typeof _ts; only make the function shape of ts available, while the interfaces and type aliases and other type information is not accessible.
Expected behavior:
No errors.
Actual behavior:
The error TS1063: An export assignment cannot be used in a namespace occurs, but in VSCode, if the file is named globals.d.ts this error does not occur. 🤷♂ In all cases the code above does work like expected, making both the functional and type exports of the namespace available for code to be checked against.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo la diagnostica con lo snippet di dichiarazione fornito, quindi confrontala con il comportamento quando il file si chiama globals.d.ts. Leggi le dichiarazioni correlate in /lib/typescript.d.ts e il contesto di runtime in /lib/typescript.js. Il lavoro è completato quando il pattern valido non segnala alcun errore e conserva sia le esportazioni funzionali sia quelle di tipo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100