microsoft / microsoft/TypeScript
[Bug Fix]: Bring parity to JS declaration generation for classes with static private members to match TS declaration output.
@weswigham y travaille déjà.
Depuis le 12/12/2024.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.