Skip to content

fix(parser): JSDoc @template replaces an empty type parameter list - #114

Open
THEtheChad wants to merge 3 commits into
pingdotgg:mainfrom
THEtheChad:fix/reparser-empty-type-params
Open

THEtheChad wants to merge 3 commits into
pingdotgg:mainfrom
THEtheChad:fix/reparser-empty-type-params

Conversation

@THEtheChad

Copy link
Copy Markdown

In a JS file, /** @template T */ function f<>() {} reports TS1098 "Type parameter list cannot be empty" in tsc-rs. Go tsc reports nothing, and with declaration it emits declare function f<T>(): void;. A @returns {T} on the same function also gives TS2304 "Cannot find name 'T'" instead of Go's TS2355.

Cause: Go's reparser (reparser.go:459) checks fun.TypeParameters() == nil. That accessor returns the list's nodes, and Go's parser stores nil nodes for an empty <> (core/arena.go:55), so the @template parameters replace the empty list. The port checked whether the list itself was nil, which it never is for <>.

The checker made the same mistake at checker.go:10415. A function expression with <> skipped the inference from its annotated parameters, so g(function <>(x: string | number) {}, "a") inferred string instead of Go's string | number.

Fix: both sites use type_parameters().is_empty(), the port of Go's accessor. The class branches really do check the list in Go and are unchanged. The lib parse blobs are regenerated because reparser.rs is part of their key.

Tests: tsctests/empty_type_parameters.rs (4 tests, expected output from Go tsc at 3e9236361fa9). Output and exit code are byte-identical to Go for <>, < >, </* c */>, methods, function expressions, d.ts emit and the inference case. Found with a differential fuzzer run against the Go oracle at the pin.

🤖 Generated with Claude Code

THEtheChad and others added 3 commits October 30, 2026 18:13
Go reparser.go:459 tests `fun.TypeParameters() == nil`, the Nodes of the
list, which the Go parser leaves nil for an empty `<>` (Arena.Clone of an
empty slice is nil). The port tested the list itself, so `/** @template T */
function f<>() {}` in a JS file kept the empty list: TS1098, TS2304 for the
template names, and no type parameters in the declaration emit. The class
branches test the list in Go too and are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ameters

Go checker.go:10415 tests `node.TypeParameters() == nil`, which is also
true for an empty `<>` list. The port tested the list, so
inferFromAnnotatedParametersAndReturn did not run for `function <>(x: A)`
and the inferred type could differ (`string` where Go gives
`string | number`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
frontend/parser/reparser.rs is a key source of lib_parse.bin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 31, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ad5d369e-42fc-470b-a002-551b6fa7e58f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

This branch has not been deployed

No deployments
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.

1 participant