Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve formatting for empty tuple types (#11884)
* Don't print trailing comma when tuple is empty * Add tests * Don't print softline * Add tests * Update tests * Add changelog * Update changelog_unreleased/typescript/11884.md Co-authored-by: fisker Cheung <lionkay@gmail.com> * Fix names Co-authored-by: fisker Cheung <lionkay@gmail.com>
- Loading branch information
1 parent
62ede8b
commit e17404e
Showing
4 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#### Improve formatting for empty tuple types (#11884 by @sosukesuzuki) | ||
|
||
<!-- prettier-ignore --> | ||
```tsx | ||
// Input | ||
type Foo = | ||
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooo extends [] | ||
? Foo3 | ||
: Foo4; | ||
|
||
// Prettier stable | ||
type Foo = Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooo extends [ | ||
|
||
] | ||
? Foo3 | ||
: Foo4; | ||
|
||
// Prettier stable (tailingCommma = all) | ||
// Invalid TypeScript code | ||
type Foo = Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooo extends [ | ||
, | ||
] | ||
? Foo3 | ||
: Foo4; | ||
|
||
// Prettier main | ||
type Foo = | ||
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooo extends [] | ||
? Foo3 | ||
: Foo4; | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/format/typescript/tuple/trailing-comma-for-empty-tuples.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong = [] | ||
|
||
type Foo = Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooo extends [] ? Foo3 : Foo4; |