microsoft / microsoft/TypeScript

Should go to type declaration on arrays if possible

Abierto
#55,196 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Experience Enhancement Help Wanted Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

Suggestion

@Andarist thank you so much for fixing #14148, however, it doesn't work if we modify the code so the array is part of the desired type:

type B = {}[]
declare const goToTypeDefinitionOnMe: B

{} can also be literal, like string union. It displays the type definition B only if it is not an empty object.

STR

Go to type definition on goToTypeDefinitionOnMe in vscode.

Actual behavior

It reveals only lib.d.ts Array definitions.

Expected behavior

It should primarily reveal type B. Like as it does with the following code:

type B = { foo }[]
declare const goToTypeDefinitionOnMe: B

Of course, I faced this problem in more complicated examples. However I decided to simply the case here.

I understand that in some cases, unfortunately, information of the target type (e.g. string union) is lost. However I tried to debug here
https://github.com/microsoft/TypeScript/blob/2623fe7049cfd837552c1dfab0b3c4687f0ec8a2/src/services/goToDefinition.ts#L444
and I saw that resolvedType actually has resolvedType.aliasSymbol.declarations[0] which is what I'm looking for (it points to type B)! So as I understand we can improve behavior in the following case, right?

🔍 Search Terms

go to type definition on array types still point to array from lib.d.ts

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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 comportamiento en VS Code con el ejemplo del tipo array y, después, empieza en src/services/goToDefinition.ts alrededor del manejo de resolvedType al que se hace referencia. Se considera terminado cuando go-to-definition abre principalmente el tipo B para un array cuyo tipo de elemento es un objeto vacío o un tipo literal, conservando el comportamiento existente para los demás casos.

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

Evaluación

Stack tecnológico
typescript, vscode
Área
devtools
Tipo de issue
Nueva funcionalidad
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.