microsoft / microsoft/TypeScript

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

Abierto
#60,744 2 comentarios 1 reacción 1 asignado Ver en GitHub

@weswigham ya está trabajando en esto.

Desde el 12/12/2024.

Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.