Skip to content

Add overload tag #900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

sandersn
Copy link
Member

@overload emits a synthetic bodyless function declaration, which then behaves just like a real overload.

To make errors behave nicely, I had to omit some position checks; those errors can't apply to @overload tags anyway. I also removed one @overload-specific error and went back to the standard one.

I ran into the same problem with @template (type parameters) as I saw with @typedef. The fix requires setting Host to a parent synthetic node on nested synthetic nodes, because name resolution always prefers Host for those nodes. I created the signature first, with Parameters and Type nil, so that I could use makeNewType to set the Host in the usual way when creating parameters and return type. Then I set the Parameters and Type afterward.

I applied that same fix to @typedef but it still didn't instantiate the type parameters correctly, so I'm going to fix it in a separate PR.

There is a good deal of churn because I also removed JSDocPropertyTag as a separate type -- it's now a JSDocParameterTag with a different kind, just like JSExportAssignment and other reparsed nodes.

sandersn added 2 commits May 21, 2025 09:34
@overload emits a synthetic bodyless function declaration, which then
behaves just like a real overload.

To make errors behave nicely, I had
to omit some position checks; those errors can't apply to @overload tags
anyway. I also removed one @overload-specific error and went back to the
standard one.

I ran into the same problem with @template as I saw with @typedef, which
means that name lookup fails on all @template tags as far as I can tell.
The fix requires setting Host to a parent synthetic node on nested
synthetic nodes, because name resolution always prefers Host for those nodes.

I applied my fix but it still didn't instantiate the type parameters
correctly, so I'm going to fix it in a separate PR.
- Extract question token creation to a function.
- Create a signature with a bunch of nil fields, and set them at the
  end, allowing makeNewType to set the host in the standard way.
- Also, move question token creation for parameters so that it's created
  even if there's no type on the parameter tag.
@Copilot Copilot AI review requested due to automatic review settings May 21, 2025 17:35
Copy link
Contributor

@Copilot 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

Adds support for JSDoc @overload tags by emitting synthetic overload declarations and updates related JSDoc tag handling, AST nodes, binding, checking, and encoder logic.

  • Implemented @overload parsing in reparser.go and synthetic signature creation
  • Unified JSDocPropertyTag and JSDocParameterTag into a single tag type with shared factory methods
  • Updated checker, binder, AST, and encoder to respect NodeFlagsReparsed and new tag kinds
  • Regenerated baseline snapshots for various overload and type cases

Reviewed Changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
testdata/.../jsFileMethodOverloads3.* Updated symbol and error baselines for overloads
testdata/.../jsFileMethodOverloads2.* Updated types and symbols baselines for overloads
testdata/.../jsFileMethodOverloads.* Updated types and symbols baselines for overloads
testdata/.../jsFileFunctionOverloads2.* Updated types and symbols baselines for overloads
testdata/.../jsFileFunctionOverloads.* Updated types and symbols baselines for overloads
internal/parser/reparser.go Added @overload support and makeQuestionIfOptional helper
internal/checker/checker.go Skips synthetic overload declarations by flag
internal/binder/binder.go Extends error-range logic for reparsed nodes
internal/ast/ast.go Merged property/parameter tag types and accessors
internal/api/encoder/encoder.go Adjusted encoder masks for unified JSDoc tags
Comments suppressed due to low confidence (1)

internal/ast/ast.go:9136

  • [nitpick] The method name UpdateJSDocParameterTag now handles both parameter and property tags; consider renaming it to UpdateJSDocParameterOrPropertyTag for clarity.
func (f *NodeFactory) UpdateJSDocParameterTag(kind Kind, node *JSDocParameterTag, tagName *IdentifierNode, name *EntityName, isBracketed bool, typeExpression *TypeNode, isNameFirst bool, comment *NodeList) *Node {

- /**
- * @overload
- ~~~~~~~~
+!!! error TS7010: 'id', which lacks return-type annotation, implicitly has an 'any' return type.
Copy link
Member

Choose a reason for hiding this comment

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

This is just the wrong error message, no? JSDoc overloads are supposed to use the version without a declaration name because they're nameless in the source, right? Even if the synthetic one we make now copies the host function's name. As-is, this error is kinda ambiguous, since nowhere does id appear in the overload descriptor.

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree and collapsed the two intentionally, but if you feel strongly I can change it back.

The reason I like having the name in the error message is that the function name appears a few lines after the tag in the source text. When I read the diff, I feel like the Strada error message withholds useful information on a technicality.

Copy link
Member

Choose a reason for hiding this comment

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

As-is, to me, the error feels like it's talking about the host declaration rather than the underlined one, and the span's in the wrong place.

Copy link
Member

@weswigham weswigham May 27, 2025

Choose a reason for hiding this comment

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

If you wanted to compromise, the message This overload of 'id' lacks a return-type annotation and implicitly has an 'any' return type. would be more apt, I think.

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.

2 participants