Merge pull request #24312 from Kingwl/multiline-type-literal-formatter

fix wrong formatting with multiline type literals with IntersectionTy…
This commit is contained in:
Mohamed Hegazy 2018-05-22 10:06:24 -07:00 committed by GitHub
commit 9d57903630
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View file

@ -569,6 +569,12 @@ namespace ts.formatting {
return childKind !== SyntaxKind.JsxClosingElement;
case SyntaxKind.JsxFragment:
return childKind !== SyntaxKind.JsxClosingFragment;
case SyntaxKind.IntersectionType:
case SyntaxKind.UnionType:
if (childKind === SyntaxKind.TypeLiteral) {
return false;
}
// falls through
}
// No explicit rule for given nodes so the result will follow the default value argument
return indentByDefault;

View file

@ -0,0 +1,37 @@
/// <reference path='fourslash.ts' />
//// type NumberAndString = {
//// a: number
//// } & {
//// b: string
//// };
////
//// type NumberOrString = {
//// a: number
//// } | {
//// b: string
//// };
////
//// type Complexed =
//// Foo &
//// Bar |
//// Baz;
format.document();
verify.currentFileContentIs(`type NumberAndString = {
a: number
} & {
b: string
};
type NumberOrString = {
a: number
} | {
b: string
};
type Complexed =
Foo &
Bar |
Baz;`);