microsoft / microsoft/TypeScript

Typecheck code blocks in jsdoc

Abierto
#62,383 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

### 🔍 Search Terms

jsdoc typecheck

### ✅ Viability Checklist

- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [x] This wouldn't change the runtime behavior of existing JavaScript code
- [x] This could be implemented without emitting different JS based on the types of the expressions
- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [x] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- [x] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals

### ⭐ Suggestion

When a codeblock is created in jsdoc, apply typechecking on it as if it were part of the code in the file.

### 📃 Motivating Example

I create a method that has a non-trivial function signature (example is contrived)
```ts
type OtherType = { data: TData };
class Class {
doSomething(arg: OtherType): void;
}
```
I would like to document the idiomatic usage in jsdoc
```ts
/**
* Does something, example:
* ```ts
* const cls = new Class<{ x: number }>();
* cls.doSomething({ data: { x: 1, y: 2 } });
* ```
*/
```
If the function signature or underlying types change in any way, the typechecker will tell me to update the usages, but not the example.
The example becomes outdated potentially unknowingly, potentially causing bad code that could have been prevented if the example was typechecked.

### 💻 Use Cases

1. What do you want to use this for?

Typecheck code blocks in jsdoc

2. What shortcomings exist with current approaches?

Relying on implementations as the idiomatic way when the example in the jsdoc is intended the be the idiomatic way.

3. What workarounds are you using in the meantime?

Inspection

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

No se nombran archivos, pruebas ni puntos de entrada. La investigación debe identificar los bloques de código JSDoc y los puntos de entrada de la comprobación de tipos, y después definir pruebas que demuestren que los ejemplos se comprueban con respecto a las declaraciones circundantes sin cambiar el JavaScript emitido.

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

Evaluación

Stack tecnológico
javascript, typescript
Área
compilers, documentation
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.