Skip to content

Conversation

@ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Oct 30, 2025

This PR implements rules for mixing of @type, @param, @return, and @template JSDoc annotations and removes the restriction from #1468 that made it an error to mix @type with any of the other annotations. The specific rules implemented by the PR are:

  • @type on a function is applicable when there are no preceding @param, @return, or @template annotations and no @type annotations on the function's parameters.
  • @param for a parameter is applicable when there is no applicable @type annotation for the function and no @type annotation on the parameter.
  • @return is applicable when there is no applicable @type annotation for the function.
  • @template is applicable when there is no applicable @type annotation for the function.
  • @type on a parameter is always applicable.

It isn't an error for an annotation to be inapplicable. Rather, the type specified in the annotation is simply ignored.

These rules aren't necessarily ideal (whatever that might be), but they are consistent and enforceable without excessively complicated logic.

Fixes #1970.

@ahejlsberg ahejlsberg requested review from Copilot, jakebailey and sandersn and removed request for Copilot October 30, 2025 01:07
@jakebailey
Copy link
Member

Needs a go generate ./internal/diagnostics to resync the diags that were modified.

Copilot AI review requested due to automatic review settings October 30, 2025 01:47
Copy link
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.

Pull Request Overview

This PR changes the JSDoc tag conflict resolution behavior in JavaScript files. Instead of reporting errors when @type tags appear alongside @param, @return, or @template tags, the compiler now implements a priority system where certain tags take precedence based on their order and presence.

  • Implements order-based precedence for JSDoc tags: @type is only applicable when no @param, @return, or @template tags precede it, and parameter-level @type annotations take precedence
  • Updates the parser to check for FullSignature to determine if a function-level @type has been applied, preventing conflicting tags from overriding it
  • Simplifies checker logic by removing the conflict error diagnostic and streamlining signature resolution to always prefer @type tag signatures when present

Reviewed Changes

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

Show a summary per file
File Description
testdata/tests/cases/conformance/jsdoc/jsdocTypeParameterTagConflict.ts Updated test cases to verify the new precedence behavior with various orderings of @type, @param, @return, and @template tags
testdata/baselines/reference/conformance/jsdocTypeParameterTagConflict.* Updated baseline outputs showing types resolved according to the new precedence rules
internal/parser/reparser.go Added checks for FullSignature and TypeParameterList to enforce tag precedence during parsing
internal/diagnostics/extraDiagnosticMessages.json Removed the error diagnostic for @type tag conflicts
internal/diagnostics/diagnostics_generated.go Removed the generated error message constant
internal/checker/relater.go Removed special handling for JSDoc type predicates from @type tags
internal/checker/checker.go Removed error checks for conflicting tags and simplified signature resolution

@ahejlsberg ahejlsberg added this pull request to the merge queue Oct 30, 2025
Merged via the queue into main with commit 179ff49 Oct 30, 2025
29 checks passed
@ahejlsberg ahejlsberg deleted the fix-1970 branch October 30, 2025 04:44
@JakobJingleheimer
Copy link

Thanks!

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.

TS8040: A JSDoc '@type' tag may not occur with a '@param' or '@returns' tag.

4 participants