microsoft / microsoft/TypeScript

[Bug Fix]: Bring parity to JS declaration generation for classes with static private members to match TS declaration output.

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

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

2024年12月12日 から。

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

説明

Acknowledgement
  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment
  • TS versions: All recent (5.x)

Problem:
When generating type declarations for ESM / Javascript classes with private static members including properties and methods the code path for JS declaration generation does not take into account the private / # state of the symbol or associated declaration when collecting static members. This results in those class members becoming publicly visible in the generated declarations and furthermore with the mangled internal names assigned to private declarations in the binding process.

You can see the problem in this TS playground example. Notice the difference in the output .d.ts when switching between Javascript and Typescript via the TS Config options. The JS declaration generation path does not filter out static private class members nor adds the #private identifier based on static private members.

Please see this brief overview video showing the current results on TS 5.7.2:
https://github.com/user-attachments/assets/85e558fa-58e9-4192-b3ed-16c749e78b46

Expected Result:
That static private members of a class are removed from generated public type declarations in the same exact way for JS & TS source files. This is also valuable because this allows import elision to occur for any type references associated with static private members that may otherwise not be referenced in the public declarations.

Fix:
I have added the appropriate filtering step in src/compiler/checker.ts -> serializeAsClass to remove private static members from passing through to the output declarations. I have ensured that the #private identifier is correctly added for classes that only have private static members. I have added a test case and baseline reference. You can view the code changes here.

PR:
Upon review and acceptance of this bug & my proposed fix I can provide a timely submission of a PR.

Future:
I am interested in fixing more JSDoc / Javascript / declaration generation issues improving support. I'm familiar with TS AST and the TS code area of impact in the declaration generation pipeline.

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

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

はじめの一歩

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

評価

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

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

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