microsoft / microsoft/TypeScript

Should go to type declaration on arrays if possible

Open
#55,196 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Help Wanted Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior in VS Code with the array type example, then start at src/services/goToDefinition.ts around the referenced resolvedType handling. Done means go-to-definition primarily opens type B for an array whose element type is an empty object or literal type, while preserving the existing behavior for other cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vscode
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.