Skip to content

TypeScript: ECMAScript private method overloading results in syntax error #59102

@davecardwell

Description

@davecardwell

Version

v24.4.1

Platform

Darwin mac.lan 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:33 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T8122 arm64

Subsystem

No response

What steps will reproduce the bug?

Node.js’ type stripping results in a syntax error when using function overloading with ECMAScript private methods.

class Foo {
  #bar(baz: string): string;
  #bar(baz: number): number;
  #bar(baz: string | number): string | number;
  #bar(baz: string | number): string | number {
    return baz;
  }

  public bar(baz: string | number): string | number {
    return this.#bar(baz);
  }
}


console.log(new Foo().bar(42));

This example is valid TypeScript and compiles as expected under tsc.

How often does it reproduce? Is there a required condition?

Consistently.

What is the expected behavior? Why is that the expected behavior?

I expect the example to run and output 42.

It compiles under the tsc command and the output can be executed with Node.js:

// output of:
// pnpm --package typescript dlx tsc --target es2022 index.ts

class Foo {
    #bar(baz) {
        return baz;
    }
    bar(baz) {
        return this.#bar(baz);
    }
}
console.log(new Foo().bar(42));

What do you see instead?

/private/tmp/foo/index.ts:2
  #bar(baz        )        ;
                           ^

SyntaxError: Unexpected token ';'
    at wrapSafe (node:internal/modules/cjs/loader:1624:18)
    at Module._compile (node:internal/modules/cjs/loader:1666:20)
    at Object..js (node:internal/modules/cjs/loader:1824:10)
    at Module.load (node:internal/modules/cjs/loader:1427:32)
    at Module._load (node:internal/modules/cjs/loader:1250:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:152:5)
    at node:internal/main/run_main_module:33:47

Node.js v24.4.1

Additional information

Reported to swc-project/swc#10884.

Metadata

Metadata

Assignees

No one assigned

    Labels

    strip-typesIssues or PRs related to strip-types support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions