microsoft / microsoft/TypeScript

JS declaration emit invalid when typedefs present and `module.exports` is assigned a non-identifier

Offen
#56,002 0 Kommentare 1 Reaktion 1 zugewiesene Person Auf GitHub ansehen

@sandersn arbeitet bereits daran.

Seit 06.10.2023.

Bug Domain: Declaration Emit
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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;

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.