Skip to content

Ignore the synthetic this parameter when matching JSDoc params - #65576

Closed
5 (tydavid5) wants to merge 2 commits into
microsoft:mainfrom
tydavid5:fix/jsdoc-this-destructured-param-65524
Closed

5 (tydavid5) wants to merge 2 commits into
microsoft:mainfrom
tydavid5:fix/jsdoc-this-destructured-param-65524

Conversation

@tydavid5

Copy link
Copy Markdown

Fixes #65524

This is a 7.0 regression. A Sajith Ariyarathna (@this) tag inserts a synthetic this parameter at index 0, which shifted positional PARAM matching by one. The first real parameter was left unmatched, so a destructured parameter got no type and was reported as implicitly any (TS7031), and its valid PARAM tag was reported as unmatched (TS8024). The same code without Sajith Ariyarathna (@this) was fine on every version, and TS 5.9.3 had no errors.

Both findMatchingParameter and checkUnmatchedJSDocParameters now skip a leading this parameter when computing PARAM positions. This covers the synthetic parameter from Sajith Ariyarathna (@this) as well as an explicitly declared this parameter.

A regression test covers the reported repro plus controls for the same code without Sajith Ariyarathna (@this) and a named first parameter with Sajith Ariyarathna (@this).

I verified the repro before the fix (TS8024 at a.js 3,31 and TS7031 at a.js 5,28) and after (no errors), and ran the new compiler test plus the jsdoc and this test groups and the parser and checker package tests, all passing.

A @this tag inserts a synthetic this parameter at index 0, which shifted positional @PARAM matching by one. The first real parameter was left unmatched, so a destructured parameter got no type and was reported as implicitly any (TS7031), and its valid @PARAM tag was reported as unmatched (TS8024).

Both findMatchingParameter and checkUnmatchedJSDocParameters now skip a leading this parameter when computing @PARAM positions. This covers the synthetic parameter from @this as well as an explicitly declared this parameter. Adds a compiler test with the reported case plus the same code without @this and a named parameter with @this as controls.

Fixes microsoft#65524
Copilot AI balanced review requested due to automatic review settings November 19, 2026 08:10
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 19, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Nov 19, 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.

🟡 Changes recommended

The receiver-skipping logic causes false TS8024 suggestions for documented TypeScript this parameters and misaligns tags for subsequent destructured parameters.

1 open issue
What changed in this PR

This PR addresses the TypeScript 7.0 regression in #65524, where JSDoc @this shifted positional @param matching and caused false diagnostics for destructured parameters.

Changes:

  • Adjust parser and checker matching to skip a leading this parameter.
  • Add a regression test with controls for functions without @this and with named parameters.
  • Record expected type and symbol baselines.
File Description
tsc/​testdata/​tests/​cases/​compiler/​jsdocThisTagWithDestructuredParameter.ts Adds the regression case and controls.
tsc/​testdata/​baselines/​reference/​compiler/​jsdocThisTagWithDestructuredParameter.types Records expected parameter and return types.
tsc/​testdata/​baselines/​reference/​compiler/​jsdocThisTagWithDestructuredParameter.symbols Records expected symbol bindings.
tsc/​internal/​parser/​reparser.go Adjusts positional JSDoc parameter matching.
tsc/​internal/​checker/​jsdoc.go Adjusts unmatched-tag checks for leading receivers.

Review effort: Balanced

Comment thread tsc/internal/checker/jsdoc.go Outdated
Comment on lines +32 to +34
if len(functionParameters) > 0 && (functionParameters[0].Name().Kind == ast.KindThisKeyword || ast.IsThisIdentifier(functionParameters[0].Name())) {
parameterOffset = 1
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed. Both findMatchingParameter and checkUnmatchedJSDocParameters now apply the offset only when the receiver has no corresponding PARAM tag. If a PARAM tag names this, the existing matching is kept. Added a regression test for the documented receiver in both forms, a JavaScript file with Sajith Ariyarathna (@this) plus PARAM this, and a TypeScript file with an explicitly declared this receiver.

Copilot review on PR microsoft#65576 caught a case the first version of this fix missed. The leading this parameter was skipped unconditionally, which was right when the parameter is synthetic, inserted from a @this tag, because the @PARAM tags are written without counting it. But when the receiver is documented with a @PARAM this tag, the tags are written counting it, so skipping it misaligned everything: the following @PARAM tag was reported as unmatched with a false TS8024, and in JavaScript files the receiver type was applied to the wrong parameter.

Both findMatchingParameter and checkUnmatchedJSDocParameters now apply the offset only when the receiver has no corresponding @PARAM tag. If any @PARAM tag names this, the existing name and position matching is kept. A regression test covers the documented receiver in both forms, a JavaScript file with @this plus @PARAM this, and a TypeScript file with an explicitly declared this receiver, with suggestion capture on so the TypeScript case is checked too.

Fixes microsoft#65524
@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Nov 19, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

[7.0 regression] JSDoc @this breaks @param matching for destructured parameter (TS8024)

3 participants