microsoft / microsoft/TypeScript

Suggestion: make hover tooltips more readable by showing the generic parameters names instead of their value (in some cases)..

Abierto
#62,634 3 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

tooltip generic parameters
expandable hover
format hover

Related issues:

I searched for both open and close issues, didn't found a duplicate, maybe I didn't use the correct search terms.

✅ Viability Checklist
⭐ Suggestion

For readability sake, when displaying type info in the hover tooltip, it is better (in some cases) to show the generic parameters' names instead of their value.

The rule could be that when a generic type parameter exceed a certain size, to show its name instead of its value (with the possibility to expand it).

📃 Motivating Example
function foo<T extends Record<string, any>>(o: T) {
    return class X {
        constructor(a: number, b: string) {}
    }
}

const X = foo({
    f1: 34, f2: 34, f3: 34, f4: 34, f5: 34, f6: 34, f7: 34, f8: 34, f9: 34, f10: 34,
});

new X(12, "ok")

Playground Link

When editing new X() arguments, the following tooltip is showing:

X(a: number, b: string): foo<{ f1: number; f2: number; f3: number; f4: number; f5: number; f6: number; f7: number; f8: number; f9: number; f10: number; }>.X

This can quickly become hard to read if the generic parameters are complex. The following would be easier to read (while keeping the ability to expand it*).

X(a: number, b: string): foo<T>.X

_*Well, maybe expansion is not always the solution, and instead of showing the full type definition, to be able to browse the type, e.g. clicking on "T" to show its value (in another hover or by expanding it). Could be more appropriate when we want more precision on one part of the type, not on the whole type.

*Note: TS Playground doesn't seem to have the expandable hover tooltip feature._

💻 Use Cases
  1. What do you want to use this for?

Improve hover tooltip readability.

  1. What shortcomings exist with current approaches?

Tooltip can be hard to read.

  1. What workarounds are you using in the meantime?

Some VSCode extensions, enable to "prettify" hover tooltips to some extends (e.g. MylesMurphy.prettify-ts).

The alternative would be to format the output to improve readability:

X(
        a: number,
        b: string
): foo<
            { f1: number; f2: number; f3: number; f4: number; f5: number; f6: number; f7: number; f8: number; f9: number; f10: number; }
      >.X

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 el ejemplo motivador utilizando el TypeScript Playground enlazado e inspecciona la salida del tooltip de hover indicada. No se especifica ningún archivo del repositorio, prueba ni punto de entrada de la implementación, así que primero hay que aclarar el umbral de tamaño, el comportamiento de expansión y la visualización esperada de los parámetros genéricos. La tarea estará terminada cuando la salida del hover sea más legible, manteniendo al mismo tiempo una forma adecuada de inspeccionar el tipo subyacente.

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

Evaluación

Stack tecnológico
typescript
Área
developer-experience, tooling
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
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.