microsoft / microsoft/TypeScript
JS declaration emit invalid when typedefs present and `module.exports` is assigned a non-identifier
Ouverte
@sandersn y travaille déjà.
Depuis le 6/10/2023.
Bug
Domain: Declaration Emit
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
Reported at https://github.com/microsoft/TypeScript/issues/46011#issuecomment-1748749050
Repro steps
Run declaration emit on this JS
/** @typedef {string} S */
/** @type {any} */
module.exports = "";
Expected behavior
declare const _exports: any;
export = _exports;
declare namespace _exports {
export { S };
}
type S = string;
The declaration file is error-free.
Actual behavior
declare const _exports: any;
export = _exports;
export type S = string;
The declaration file errors with An export assignment cannot be used in a module with other exported elements.
Additional info
Declaration emit works as expected if module.exports is assigned to an identifier that doesn’t necessitate the _exports temp variable synthesis:
/** @typedef {string} S */
/** @type {any} */
const x = "";
module.exports = x;
produces:
export = x;
/** @typedef {string} S */
/** @type {any} */
declare const x: any;
declare namespace x {
export { S };
}
type S = string;
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.
Évaluation
Cette issue n'a pas encore été évaluée.