microsoft / microsoft/TypeScript

Undocumented = operator syntax in Generic Constraining

Abierto
#30,337 4 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

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

Descripción

In the declaration file for Fastify (https://github.com/fastify/fastify/blob/master/fastify.d.ts) there is some TypeScript code I do not recognize and cannot find another example of in the TypeScript documentation:

declare function fastify<
  HttpServer extends (http.Server | http2.Http2Server) = http.Server,
  HttpRequest extends (http.IncomingMessage | http2.Http2ServerRequest) = http.IncomingMessage,
  HttpResponse extends (http.ServerResponse | http2.Http2ServerResponse) = http.ServerResponse
>(opts?: fastify.ServerOptions): fastify.FastifyInstance<HttpServer, HttpRequest, HttpResponse>;

I recognize the Generic constraint syntax with the extends keyword, but what about the = http.Server part? Is this like a default parameter or something?

Whatever this syntax means it should be better documented.

I tried googling for this syntax by searching

  • typescript generic constraint
  • typescript generic constraint assignment
  • typescript generic defaults

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

Comienza leyendo la declaración genérica en fastify.d.ts de Fastify y compara su sintaxis de restricción y valor predeterminado con las búsquedas de la documentación de TypeScript indicadas en el issue. Documenta qué significan las partes = http.Server y añade un ejemplo o una explicación en la documentación de TypeScript correspondiente; se considera terminado cuando los recién llegados pueden encontrar y entender esta sintaxis.

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

Evaluación

Stack tecnológico
typescript
Área
documentation
Tipo de issue
Documentación
Dificultad
2/5
Tiempo estimado
1-3 horas
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.