fix(checker): check type expressions on unmatched JSDoc @param tags#3974
Closed
Zelys-DFKH wants to merge 1 commit into
Closed
fix(checker): check type expressions on unmatched JSDoc @param tags#3974Zelys-DFKH wants to merge 1 commit into
Zelys-DFKH wants to merge 1 commit into
Conversation
When a @param tag's name doesn't match any function parameter, checkUnmatchedJSDocParameters emits TS8024 but never called checkSourceElement on the tag's type expression. This caused diagnostics like TS2314 (generic type missing type arguments) to be silently skipped for unmatched params, while matched params correctly reported them via checkVariableLikeDeclaration -> checkSourceElement. After emitting TS8024 (or skipping for isNameFirst), call checkSourceElement on the tag's type expression if present. This mirrors what the matched-param path does. Fixes microsoft#3742 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
6392fc8 to
29e83b0
Compare
Member
|
Closing automated PRs; please don't run automated coding tools against this repo. We're fully able to do that ourselves. |
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 #3742
Hat tip to @hkleungai: the side-by-side tsc/tsgo output in that thread made the gap easy to trace.
checkUnmatchedJSDocParameterscorrectly emits TS8024 when a@paramname doesn't match any real parameter, but it drops the type expression without checking it. So@param {Record} baron a zero-parameter function gives you TS8024 and silently misses TS2314 ("Generic type 'Record' requires 2 type argument(s)"). tsc reports both.Analysis
For matched params, the type expression reaches
checkSourceElementthroughcheckVariableLikeDeclaration, which is what triggerscheckTypeReferenceNodeand eventually TS2314 for things likeRecord. For unmatched params, the loop callserrorOrSuggestionfor TS8024 and then moves on. The type expression is never touched.Fix
After the TS8024 emission (or the
isNameFirstskip), check the tag's type expression if present. Two guards are needed:JS files only. In
.tsfiles, JSDoc types are documentation, not the type system. Without theisJsgate, a local variable name used as a@paramtype (common in tsc's own checker.ts) incorrectly surfaces TS2304 ("Cannot find name 'X'"). Every other JSDoc type check in the checker observes the same boundary.Skip signature types.
KindFunctionType,KindConstructorType,KindCallSignature,KindConstructSignature, andKindIndexSignatureall dispatch tocheckSignatureDeclaration, which callscheckParameteron the signature's parameter list. Those parameters are not symbol-bound inside JSDoc type expressions, sogetSymbolOfDeclarationreturns nil, causing a nil-pointer panic. Callback-style@param {(x: T) => U} fntypes are excluded from checking for now; recovering diagnostics from inside those signatures is a separate, harder problem.Test
Added
testdata/tests/cases/compiler/jsdocUnmatchedParamTypeChecked.ts: a JS file with@param {Record} baron a zero-parameter function. The baseline shows both TS2314 and TS8024, matching tsc output.Copilot Checklist
I successfully ran these commands at the end of my session, and they completed without error: