Skip to content

Fix false positive TS8030 for JSDoc @type on optional interface methods - #64052

Open
종윤 (jyx-07) wants to merge 1 commit into
microsoft:mainfrom
jyx-07:fix/jsdoc-optional-method-8030
Open

Fix false positive TS8030 for JSDoc @type on optional interface methods#64052
종윤 (jyx-07) wants to merge 1 commit into
microsoft:mainfrom
jyx-07:fix/jsdoc-optional-method-8030

Conversation

@jyx-07

@jyx-07 종윤 (jyx-07) commented Aug 27, 2026

Copy link
Copy Markdown

Fixes #63754.

When a JSDoc Type (@type) annotation on a function resolves through an
optional interface member (e.g. Example['method'] where method is
optional), the resolved type includes | undefined. Three call sites
in checker.go fed that raw union directly into signature-lookup
helpers that don't handle unions with undefined, producing a false
TS8030 diagnostic and an implicit any for the parameter.

Fix: apply the existing removeMissingOrUndefinedType helper at
all three sites before signature resolution, matching the pattern
already used elsewhere in the checker for the same class of problem.

Added a regression test (jsdocOptionalMethodFullSignature.ts)
covering both the fixed case and an arity-mismatch case that must
still correctly report TS8030.

Verified:

  • Original repro from the issue → 0 errors
  • Genuine arity mismatches still correctly report 8030
  • Parameter is now correctly typed from the JSDoc annotation

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.

Pull request overview

Strips optional undefined from JSDoc function types before signature resolution.

Changes:

  • Normalizes JSDoc full-signature types at three checker call sites.
  • Restores contextual typing and avoids false TS8030 diagnostics.

c.checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, c.getReturnTypeFromAnnotation(node))
if node.FunctionLikeData().FullSignature != nil {
if c.getContextualCallSignature(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature), node) == nil {
if c.getContextualCallSignature(c.removeMissingOrUndefinedType(c.getTypeFromTypeNode(node.FunctionLikeData().FullSignature)), node) == nil {

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.

Added tsc/testdata/tests/cases/compiler/jsdocOptionalMethodFullSignature.ts, covering both the optional indexed-access signature (fixed) and an arity-mismatch case (still correctly reports TS8030).

When a JSDoc @type annotation on a function resolves through an
optional interface member (e.g. Example['method'] where method is
optional), the resolved type includes | undefined. Three call sites
in checker.go fed that raw union directly into signature-lookup
helpers that don't handle unions with undefined, producing a false
TS8030 diagnostic and an implicit any for the parameter.

Strip the undefined via the existing removeMissingOrUndefinedType
helper at all three sites before signature resolution, matching the
pattern already used elsewhere in the checker for the same class of
problem.
@jyx-07
종윤 (jyx-07) force-pushed the fix/jsdoc-optional-method-8030 branch from d2477a6 to f980e3c Compare August 27, 2026 12:00
@jyx-07 종윤 (jyx-07) changed the title fix: strip undefined from optional JSDoc @type before contextual typing (#63754) Fix false positive TS8030 for JSDoc @type on optional interface methods Aug 27, 2026
@jyx-07

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

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

Labels

None yet

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Diagnostic code 8030 being incorrectly generated using JSDoc @type on a function.

2 participants