Repository navigation
Ignore the synthetic this parameter when matching JSDoc params - #65534
Closed
Josué Barros (joshbarros) wants to merge 1 commit into
Closed
Josué Barros (joshbarros) wants to merge 1 commit into
Josué Barros (joshbarros) wants to merge 1 commit into
Conversation
A @this tag inserts a synthetic `this` parameter at index 0. findMatchingParameter and checkUnmatchedJSDocParameters matched @PARAM tags by their index in the original parameter list, so the shift left the first real parameter unmatched. A destructured parameter then got no type and TS8024 was reported. Skip the leading `this` parameter when computing the @PARAM position. A @this tag is not described by a @PARAM tag, so the two lists line up again. Adds the report's destructured-parameter case as a compiler test.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the JSDoc parameter-matching fix.
No open issues 🎉
What changed in this PR
Fixes #65524 by excluding the leading this parameter introduced by JSDoc @this from positional @param matching, restoring correct typing for destructured parameters.
Changes:
- Adjusts parser matching and checker diagnostics to account for the leading
thisparameter. - Adds a regression test with symbol and type baselines confirming that the destructured
titleparameter is typed asstring.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/jsdocThisTagWithDestructuredParameter.ts |
Adds the @this and destructured-parameter regression case. |
tsc/testdata/baselines/reference/compiler/jsdocThisTagWithDestructuredParameter.types |
Records correct parameter and return types. |
tsc/testdata/baselines/reference/compiler/jsdocThisTagWithDestructuredParameter.symbols |
Records expected symbol bindings. |
tsc/internal/parser/reparser.go |
Offsets positional matching when @this introduces a leading parameter. |
tsc/internal/checker/jsdoc.go |
Applies the same offset when checking unmatched JSDoc parameters. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #65524
A
@thistag inserts a syntheticthisparameter at index 0.findMatchingParameterandcheckUnmatchedJSDocParametersmatched@paramtags by their index in the original parameter list, so the shift left the first real parameter unmatched. A destructured parameter then got no type, which produced TS7031, and TS8024 was reported for the valid@param.This skips the leading
thisparameter when computing the@paramposition. A@thistag is not described by a@paramtag, so the two lists line up again. An explicitly declaredthisparameter is handled the same way.The new compiler test uses the report's destructured-parameter case. On the unfixed compiler it produces TS8024 and TS7031 and changes the type baseline; with the fix there are no diagnostics and
titleis typed.Validation:
go test ./tsc/internal/testrunner -run 'TestLocal/jsdocThisTagWithDestructuredParameter' -count=1: fails without the change, passes with it.go test ./tsc/internal/testrunner -run 'TestLocal/jsdoc' -count=1: pass.go test ./tsc/internal/parser ./tsc/internal/checker -count=1: pass.go vetand the repo'sgofmt: clean.Drafted with assistance from an AI assistant. I reviewed the diff and ran the tests above.