microsoft / microsoft/TypeScript
Incorrect error message on export assignment in `.d.ts` file
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 132
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire le diagnostic avec l’extrait de déclaration fourni, puis comparez-le au comportement lorsque le fichier est nommé globals.d.ts. Lisez les déclarations associées dans /lib/typescript.d.ts ainsi que le contexte d’exécution dans /lib/typescript.js. C’est terminé lorsque le motif valide ne signale aucune erreur tout en conservant les exports fonctionnels et de types.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 42/100