microsoft / microsoft/TypeScript

JSDoc present in mapped types is not output in generated type literals in declaration files

Abierto
#62,309 2 comentarios 6 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Domain: Declaration Emit Help Wanted Possible Improvement
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

🔎 Search Terms

generated declaration files mapped types jsdoc missing

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about: I don't believe the FAQ contains anything applicable to this.
⏯ Playground Link

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBALzgMyhEcDkCIBNMBQBApgB6SxwDGEAdgM7z1UAWxIAhnALyIB0EAEYArYlRgAKAN4E4cAPQAqRbLmK4AZXTE4tYFR0ApDQBEIVVXEXzVyCBABc-RlGC0A5hICUAGgIBfLyIaBnhSHjhmNk4+MA4oemJpO0csDkxAvhTLOVy8-ILCuXl5OAA9CrgWCAA3YlcPFHtI6oB3ejgYNjhjMwsgA

💻 Code

This is not the same issue as https://github.com/microsoft/typescript/issues/50715, that issue is about type mappings that lose the JSDoc period.

I'm talking about what happens in the .d.ts file generated for source like this where JSDoc does survive type mapping:

import z from 'zod'

export const schema = z.object({
  /**
   * Some nice JSDoc
   */
  foo: z.string(),
})

const x = schema.parse({foo: 'a'}).foo
                                // ^^^ hovering foo shows the JSDoc
🙁 Actual behavior

Hovering the parsed .foo in the source file displays the JSDoc for the property:
Image

But if I consume the same type from the generated .d.ts file, I don't get the JSDoc:

Image
🙂 Expected behavior

We should get the same JSDoc when consuming the .d.ts file as we do when consuming the source file it was generated from.

Additional information about the issue

If we look at the generated .d.ts the problem is clear: tsc isn't outputting JSDoc it has in memory for mapped type properties to the generated type literals:

import z from 'zod';
export declare const schema: z.ZodObject<{
  /**
   * Some nice JSDoc
   */
  foo: z.ZodString;
}, "strip", z.ZodTypeAny, {
  foo: string; // (tsc should have copied the JSDoc to this property)
}, {
  foo: string; // (and to this one)
}>;
//# sourceMappingURL=Schema.d.ts.map

It would at least be nice to have an option to output these copies of JSDoc, even though it would make the declaration file bigger.

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.

Línea de trabajo

Reproduce la salida de la declaración de mapped-type usando el TypeScript Playground enlazado y compara el .d.ts generado con el JSDoc del código fuente. Rastrea el declaration emitter y el manejo de propiedades de mapped-type; después, añade cobertura que demuestre que los literales de tipo generados conservan el JSDoc y verifica las declaraciones esperadas.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.