microsoft / microsoft/TypeScript

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

オープン
#56,002 コメント 0 件 リアクション 1 件 担当者 1 名 GitHub で見る

@sandersn がすでに取り組んでいます。

2023年10月6日 から。

Bug Domain: Declaration Emit
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

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;

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。