Skip to content

Commit 9d57903

Browse files
authored
Merge pull request #24312 from Kingwl/multiline-type-literal-formatter
fix wrong formatting with multiline type literals with IntersectionTy…
2 parents a8715d0 + 4b47c0c commit 9d57903

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/services/formatting/smartIndenter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,12 @@ namespace ts.formatting {
569569
return childKind !== SyntaxKind.JsxClosingElement;
570570
case SyntaxKind.JsxFragment:
571571
return childKind !== SyntaxKind.JsxClosingFragment;
572+
case SyntaxKind.IntersectionType:
573+
case SyntaxKind.UnionType:
574+
if (childKind === SyntaxKind.TypeLiteral) {
575+
return false;
576+
}
577+
// falls through
572578
}
573579
// No explicit rule for given nodes so the result will follow the default value argument
574580
return indentByDefault;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// type NumberAndString = {
4+
//// a: number
5+
//// } & {
6+
//// b: string
7+
//// };
8+
////
9+
//// type NumberOrString = {
10+
//// a: number
11+
//// } | {
12+
//// b: string
13+
//// };
14+
////
15+
//// type Complexed =
16+
//// Foo &
17+
//// Bar |
18+
//// Baz;
19+
20+
21+
format.document();
22+
verify.currentFileContentIs(`type NumberAndString = {
23+
a: number
24+
} & {
25+
b: string
26+
};
27+
28+
type NumberOrString = {
29+
a: number
30+
} | {
31+
b: string
32+
};
33+
34+
type Complexed =
35+
Foo &
36+
Bar |
37+
Baz;`);

0 commit comments

Comments
 (0)