Skip to content

When formatting TypeScript generics, a comma was incorrectly inserted in the empty array. #11878

@lsby

Description

@lsby

Prettier 2.5.0
Playground link

--parser typescript
--print-width 120
--trailing-comma all

Input:

type aabbccdd<a> = []
type kjhudifkalmcnf<obj extends Record<string, unknown>, aaddffgg extends string[] = aabbccdd<obj>> = aaddffgg extends []? never: never

Output:

type aabbccdd<a> = [];
type kjhudifkalmcnf<obj extends Record<string, unknown>, aaddffgg extends string[] = aabbccdd<obj>> = aaddffgg extends [
  ,
]
  ? never
  : never;

Expected behavior:

like:

type aabbccdd<a> = [];
type kjhudifkalmcnf<
  obj extends Record<string, unknown>,
  aaddffgg extends string[] = aabbccdd<obj>
> = aaddffgg extends [] ? never : never;

It seems to be related to the length.
This problem only occurs when the print-width is 120 and the length of the identifier is exactly this length.
In addition, it outputs on my computer as:
image

Metadata

Metadata

Assignees

Labels

lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions