microsoft / microsoft/TypeScript

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

Đang mở
#60,744 2 bình luận 1 reaction 1 người được giao Xem trên GitHub

@weswigham đang làm issue này rồi.

Từ ngày 12/12/2024.

Needs Investigation
Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.