Skip to content

Fix inlay hints for trailing required rest elements - #64363

Open
雪代 / Yukishiro (yksr-melt) wants to merge 1 commit into
microsoft:mainfrom
yksr-melt:fix/tsgo-inlay-hints-trailing-required-rest
Open

雪代 / Yukishiro (yksr-melt) wants to merge 1 commit into
microsoft:mainfrom
yksr-melt:fix/tsgo-inlay-hints-trailing-required-rest

Conversation

@yksr-melt

Copy link
Copy Markdown

Fixes #59979

Inlay parameter name hints were wrong for a rest parameter whose tuple type has required elements after the rest element, such as ...rest: [first: number, ...middle: string[], last: string]. Arguments were matched with the tuple elements from the start, so test(10, 'a', 'b', 'c') got last: on 'b' instead of 'c', and test(10, 'c') got ...middle: on 'c'.

When the number of arguments is known (there is no spread argument), the elements after the rest element are now matched from the end: the rest element gets its hint on its first argument only, and the elements after it get theirs on the last arguments. Calls with a spread argument, and tuples with no elements after the rest element, are handled as before.

Hints also stopped at the first argument whose parameter has no name, such as a destructured parameter, so foo({ a: 1 }, 2) for function foo({ a }: { a: number }, b: number) got no hint at all. Such an argument is now skipped and the following arguments still get their hints, as in the TypeScript 6.0 language service.

Testing

Added two fourslash baseline tests in tsc/internal/fourslash/tests:

  • inlayHintsRestParameters_trailingRequired_test.go: the case from the issue, an empty rest element, a rest element at the start, a preceding fixed parameter, and a tuple with no elements after the rest element.
  • inlayHintsParameterNames_destructuredParameter_test.go: a destructured parameter followed by a named parameter.

Both fail without the change. The existing inlay hint baselines are unchanged.

Local verification:

  • npx hereby check:format: passed.
  • go test ./... in tsc (what npx hereby test runs): all packages passed.
  • golangci-lint with the repo's custom build and .golangci.yml on the tsc module (what npx hereby lint runs first): 0 issues. The tools module could not be linted on my machine because some of its dependencies are not available offline; this change does not touch it.

AI assistance

I used Claude Code to help investigate the issue, write the change and the tests, and draft this description. I chose this issue, have reviewed the change, and will follow up on review feedback.

Copilot AI balanced review requested due to automatic review settings September 20, 2026 15:02
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 20, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Sep 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused implementation correctly handles the reported mappings and includes representative regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes inlay parameter hints for tuple rest parameters with trailing required elements and for parameters following destructured parameters.

Changes:

  • Maps trailing tuple elements from the final call arguments.
  • Continues hint processing after unnamed parameters.
  • Adds fourslash regression tests and baselines.
File Description
tsc/​internal/​ls/​inlay_hints.go Corrects argument-to-parameter hint mapping.
tsc/​internal/​fourslash/​tests/​inlayHintsRestParameters_trailingRequired_test.go Tests trailing required tuple elements.
tsc/​internal/​fourslash/​tests/​inlayHintsParameterNames_destructuredParameter_test.go Tests hints after destructured parameters.
tsc/​testdata/​baselines/​reference/​fourslash/​inlayHints/​inlayHintsRestParameters_trailingRequired.baseline Records expected rest-parameter hints.
tsc/​testdata/​baselines/​reference/​fourslash/​inlayHints/​inlayHintsParameterNames_destructuredParameter.baseline Records expected destructured-parameter behavior.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

// getRestTupleElementIndex returns the index of the element of a rest parameter's tuple type that the argument at the given
// index among the rest arguments corresponds to, or -1 if there is none. argumentCount is the number of rest arguments,
// or -1 if it is not known.
func getRestTupleElementIndex(elementInfos []checker.TupleElementInfo, index int, argumentCount int) int {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vaguely surprised there's no code reuse for this and sig help, which I think does something quite similar? I've definitely read code like this before somewhere, just not sure where.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Inlay parameter hints don't account for trailing required parameters

3 participants