microsoft / microsoft/TypeScript
Incorrect error message on export assignment in `.d.ts` file
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Diagnose mit dem bereitgestellten Deklarationsausschnitt zu reproduzieren, und vergleiche sie dann mit dem Verhalten, wenn die Datei globals.d.ts heißt. Lies die zugehörigen Deklarationen in /lib/typescript.d.ts und den Laufzeitkontext in /lib/typescript.js. Fertig ist die Änderung, wenn das gültige Muster keinen Fehler meldet und sowohl funktionale als auch Typ-Exporte beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100