Skip to content

Virtual TSX emits declare on function overload signatures, producing TS2384 #736

Closed

Description

@dudusotero

Summary

octane/compiler/volar (compileToVolarMappings) emits every bodyless function
declaration as declare function …, including plain TypeScript overload
signatures that carry no declare modifier in the authored .tsrx. The
implementation signature is emitted non-ambient, so TypeScript rejects the pair
with TS2384 "Overload signatures must all be ambient or non-ambient".

Function overloads are ordinary TypeScript. Nothing in
docs/differences-from-react.md or .rulesync/rules/tsrx-authoring.md excludes
them from .tsrx, and the runtime compile path (octane/compiler, compile.js)
handles them without complaint. Only the type-only virtual TSX is wrong, so the
symptom is editor diagnostics and tsrx-tsc failures on source that builds and
runs correctly.

Found while working #721.

Environment

Minimal reproduction

import { compileToVolarMappings } from 'octane/compiler/volar';

const source = `function f(a: string): string;
function f(a: number): number;
function f(a: unknown): unknown { return a; }
export const x = f('a');
`;

console.log(compileToVolarMappings(source, 'probe.tsrx').code);

Actual result

/** @jsxImportSource octane */
declare function f(a: string): string;
declare function f(a: number): number;

function f(a: unknown): unknown {
	return a;
}

export const x = f('a');

compileToVolarMappings reports no errors. Running tsc --noEmit on that
output:

d1.ts(1,18): error TS2384: Overload signatures must all be ambient or non-ambient.
d1.ts(2,18): error TS2384: Overload signatures must all be ambient or non-ambient.

Exported overloads take the same path and emit export declare function f….

Expected result

/** @jsxImportSource octane */
function f(a: string): string;
function f(a: number): number;

function f(a: unknown): unknown {
	return a;
}

declare belongs only on declarations the author wrote it on. An authored
declare function g(a: string): string; must keep it.

Root cause

The parser distinguishes the two shapes correctly. For

function f(a: string): string;        // overload signature
declare function g(a: string): string; // ambient declaration

both parse to TSDeclareFunction, with node.declare === undefined for the
overload and node.declare === true for the ambient declaration.

The printer does not read the flag.
[email protected]/src/languages/ts/index.js, TSDeclareFunction visitor:

TSDeclareFunction(node, context) {
	const kw = create_keyword_write(context, node);

	kw('declare ');   // unconditional

Compare the sibling printers in the same file, which all guard on the flag
(if (node.declare) kw('declare '), lines 680, 879, 2287, 2594).

The type-only print is delegated to @tsrx/core, which already overrides
several esrap printers for exactly this class of bug in
src/transform/jsx/helpers.js (TSModuleDeclaration is guarded there with
if (node.declare) context.write('declare ')). So the fix has an established
home in either esrap upstream or the @tsrx/core wrapper set.

Adjacent finding: bodyless class members crash the pipeline

The same family of node has a harder failure. A bodyless class member
(TSDeclareMethod) throws out of compileToVolarMappings instead of producing
a virtual TSX at all:

compileToVolarMappings('export class C { m(a: string): string; m(a: unknown): unknown { return a; } }', 'probe.tsrx');
// Error: Unhandled AST node type in mapping walker: TSDeclareMethod
//   at @tsrx/core/src/transform/segments.js:2263

export abstract class C { abstract m(a: string): string; } throws identically.
A class method with a body compiles normally. There are no occurrences in this
repository today, so this crashes no current file, but it means the editor gets
no virtual TSX at all rather than a wrong one.

Blast radius

Scanned all 881 .tsrx files under packages/*/src through
compileToVolarMappings.

Package Overload signatures wrongly emitted as declare
visx 15
all others 0

All 15 are in packages/visx/src/scale/react/useScale.tsrx (one 15-overload
useScale family) and account for all 15 TS2384 in
tsrx-tsc --noEmit -p packages/visx/tsconfig.json (445 diagnostic lines total).

declare function is emitted in exactly one package across the whole
repository, and every occurrence is this defect: there is currently no .tsrx
file with a legitimate ambient function declaration, so no output relies on the
current behavior.

The narrow footprint reflects how rarely overloads appear in .tsrx today, not
a narrow defect. Any .tsrx declaring overloads hits it unconditionally.

Ownership assessment

Octane's compiler, not @octanejs/visx. The authored useScale.tsrx is valid
TypeScript, compiles correctly through octane/compiler, and the same source in
a .ts file typechecks clean. The defect is in the type-only print reached
through octane/compiler/volar, in an esrap printer that ignores node.declare.
Working around it in visx (splitting the overload family into a separate .ts
file, or collapsing the overloads) would hide a compiler defect behind an app
change and leave every future .tsrx overload broken.

Activity

  1. added a commit that references this issue on Aug 13, 2026
    c2e77a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions