prettier / prettier/prettier

[3.9] Type unions squeeze into a single line

Open
#19,733 4 comments 18 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

lang:typescript status:needs discussion
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

I've enjoyed using Prettier for a long time, but I recently tried upgrading to prettier 3.9, but a lot of our code was reformatted to squeeze type untions into a single line for some reason? I think it's this one https://github.com/prettier/prettier/pull/18827, but it results in much worse formatted code, both for git diffs and readability.

v3.8
export type WorkerJob =
  | UpdateDataJob
  | UpdateEventsJob
  | UpdateOtherJob
  | UpdateSearchJob
  | UpdatePopularJob;

v3.9

export type WorkerJob =
  UpdateDataJob  | UpdateEventsJob  | UpdateOtherJob  | UpdateSearchJob  | UpdatePopularJob;

This 3.9 version is worse, since any changes in the type will now result in the whole line being git-diffed, while the old one had a proper diff & history tracking foreach union member.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the formatting difference with the TypeScript union example in this issue using Prettier 3.8 and 3.9, then review the behavior change in pull request #18827. Trace the formatter path responsible for type unions and add or update a regression test showing that each union member remains on its own line; done means the 3.9 output preserves the readable multiline form.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.