microsoft / microsoft/TypeScript

Typescript - inlay hints for nested labeled tuples

Open
#57,088 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: LS: Inlay Hints Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Type: Feature Request

The inlay hints for an array of labeled tuples are forgotten.

Troubleshooting steps:

  • Ensured Typescript is fully up-to-date.
  • Enabled all inlay hints in vsCode settings.

When a type is described as tuple with labels, you can use the ...args: ThatTupleType and when calling the function, the parameters retain the labels. This is working just fine.

However, when the argument is more complex, and there are nested labeled tuples within the type, the inlay hint information is lost (although the type information is still there; TypeScript still knows that the labels are on the array).

The expectation is that if I pass an array of tuples to an argument or type that expects the tuples to adhere to rules, and the type has labels, that the inlay hints should show those nested labels in the appropriate place.

The below example will showcase the issue I'm referring to, when it's run in vsCode with all inlay hints enabled:

type ArmorValueSet = [number, number, number, number, number, number];
type ArmorValueRange = [minVals: ArmorValueSet, maxVals: ArmorValueSet];

const parseArmor = (
    armorValues: ArmorValueRange[]
) => {
    console.log(armorValues);
};

parseArmor([
    [[6, 21, 36, 56, 81, 140], [20, 35, 55, 80, 110, 180]],
    [[6, 21, 36, 56, 81, 140], [20, 35, 55, 80, 110, 180]],
    [[6, 21, 36, 56, 81, 140], [20, 35, 55, 80, 110, 180]],
    [[6, 21, 36, 56, 81, 140], [20, 35, 55, 80, 110, 180]],
    [[6, 21, 36, 56, 81, 140], [20, 35, 55, 80, 110, 180]],
]);

const test = (...args: ArmorValueRange) => {
    console.log(...args);
}

test([6, 21, 36, 56, 81, 140], [20, 35, 55, 80, 110, 180]);

On line 22, minVals and maxVals are shown correctly. However, from lines 11-15, there are no inlay hints for these tuple labels. The expectation is that each of these lines should look the same as line 22 in terms of the inlay hints that are shown.

Here is a screenshot of what my vsCode editor looks like with this code present:

image

VS Code version: Code 1.85.1 (0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2, 2023-12-13T09:49:37.021Z)
OS version: Windows_NT x64 10.0.19045
Modes:

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

Start with the nested labeled-tuple example in the issue and reproduce it in VS Code with all inlay hints enabled. Compare the nested array call with the working rest-parameter call, then trace the TypeScript inlay-hint entry point responsible for tuple labels. Done means the nested minVals and maxVals labels appear at the expected positions without regressing the existing example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.