microsoft / microsoft/TypeScript
Evaluate user-defined generic type aliases on hover
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
Let's say we have a class like this:
class A
{
readonly x = 99;
s: string;
constructor(initialiser: { [K in Exclude<keyof A, 'x'>]: A[K] })
{
for (const k in initialiser) this[k] = initialiser[k];
}
}
Now, when I hover over the ctor param, VS Code shows me the type: { s: string; }.
Since I need such an initialiser for several classes, I have written a generic type alias:
type InitialiserExclude<C, Keys extends keyof C> = { [K in Exclude<keyof C, Keys>]: C[K] };
When I replace the initialiser type by InitialiserExclude<A, 'x'>, that's exactly what I see when hovering over the ctor param.
It would be very nice if VS Code evaluated such user-defined type aliases as it does with e. g. the built-in Exclude<T, U> and showed the resulting object type.
This is not only a matter of usability of the class. To create more complex initialiser types, it can be necessary to define multiple generic type aliases and use one within another, and the only way I know to check if such an initialiser works as expected is to declare a variable with that type and hover over it.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Usa los ejemplos de TypeScript del issue como reproducción: compara la salida al pasar el cursor sobre el tipo mapped inline, el Exclude integrado y el alias InitialiserExclude definido por el usuario. Empieza rastreando el comportamiento del hover del servicio de lenguaje para estos tipos. Se considera terminado cuando, al pasar el cursor sobre el parámetro del constructor, el alias definido por el usuario se expande al tipo de objeto resultante.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- developer-experience
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100