-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Open
Labels
lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)Issues affecting TypeScript-specific constructs (not general JS issues)
Description
Prettier 3.8.1
Playground link
# Options (if any):
--no-semi --parser typescriptInput:
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).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)Issues affecting TypeScript-specific constructs (not general JS issues)