Repository navigation
Ignore the synthetic this parameter when matching JSDoc params - #65576
5 (tydavid5) wants to merge 2 commits into
Conversation
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
There was a problem hiding this comment.
🟡 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
thisparameter. - Add a regression test with controls for functions without
@thisand 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
| if len(functionParameters) > 0 && (functionParameters[0].Name().Kind == ast.KindThisKeyword || ast.IsThisIdentifier(functionParameters[0].Name())) { | ||
| parameterOffset = 1 | ||
| } |
There was a problem hiding this comment.
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

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.