Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Extra semicolon between arrow function property and call signature in Interface #18858

@kokororin

Description

@kokororin

Prettier 3.8.1
Playground link

# Options (if any):
--no-semi --parser typescript

Input:

export interface MyInterface {
  someMethod: (a: number) => Promise<number>
  anotherMethod: (a: string) => Promise<string>
  (a: string): Promise<string>
}

Output:

export interface MyInterface {
  someMethod: (a: number) => Promise<number>
  anotherMethod: (a: string) => Promise<string>;
  (a: string): Promise<string>
}

Expected output:

export interface MyInterface {
  someMethod: (a: number) => Promise<number>
  anotherMethod: (a: string) => Promise<string>
  (a: string): Promise<string>
}

Why?

Even with semi: false configured, Prettier unexpectedly inserts a semicolon on line 3.

This happens specifically in a TypeScript interface when a method signature defined as an arrow function type (e.g., prop: (args) => Ret) is immediately followed by a call signature (args): Ret.

It seems Prettier is treating the subsequent ( as a potential start of a function call that requires ASI protection, but inside a TypeScript interface definition, this semicolon should not be necessary.

(Context: This was discovered while comparing output with the Oxc formatter).

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions