microsoft / microsoft/TypeScript
JS declaration emit invalid when typedefs present and `module.exports` is assigned a non-identifier
Aperta
@sandersn ci sta già lavorando.
Dal 6/10/2023.
Bug
Domain: Declaration Emit
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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;
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.
Valutazione
Questa issue non è ancora stata valutata.