Skip to content

fix(checker): check type expressions on unmatched JSDoc @param tags#3974

Closed
Zelys-DFKH wants to merge 1 commit into
microsoft:mainfrom
Zelys-DFKH:fix/3742-jsdoc-unmatched-param-type-check
Closed

fix(checker): check type expressions on unmatched JSDoc @param tags#3974
Zelys-DFKH wants to merge 1 commit into
microsoft:mainfrom
Zelys-DFKH:fix/3742-jsdoc-unmatched-param-type-check

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

@Zelys-DFKH Zelys-DFKH commented May 18, 2026

Fixes #3742

Hat tip to @hkleungai: the side-by-side tsc/tsgo output in that thread made the gap easy to trace.

checkUnmatchedJSDocParameters correctly emits TS8024 when a @param name doesn't match any real parameter, but it drops the type expression without checking it. So @param {Record} bar on 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 checkSourceElement through checkVariableLikeDeclaration, which is what triggers checkTypeReferenceNode and eventually TS2314 for things like Record. For unmatched params, the loop calls errorOrSuggestion for TS8024 and then moves on. The type expression is never touched.

Fix

After the TS8024 emission (or the isNameFirst skip), check the tag's type expression if present. Two guards are needed:

JS files only. In .ts files, JSDoc types are documentation, not the type system. Without the isJs gate, a local variable name used as a @param type (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, and KindIndexSignature all dispatch to checkSignatureDeclaration, which calls checkParameter on the signature's parameter list. Those parameters are not symbol-bound inside JSDoc type expressions, so getSymbolOfDeclaration returns nil, causing a nil-pointer panic. Callback-style @param {(x: T) => U} fn types 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} bar on 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:

  • npx hereby build
  • npx hereby test
  • npx hereby lint
  • npx hereby format

Copilot AI review requested due to automatic review settings May 18, 2026 16:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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>
@Zelys-DFKH Zelys-DFKH force-pushed the fix/3742-jsdoc-unmatched-param-type-check branch from 6392fc8 to 29e83b0 Compare May 18, 2026 18:04
@RyanCavanaugh
Copy link
Copy Markdown
Member

Closing automated PRs; please don't run automated coding tools against this repo. We're fully able to do that ourselves.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behavior difference: tsgo skip reporting invalid jsdoc type when param is missing from function signature

3 participants