fix wrong formatting with multiline type literals with IntersectionType and UnionType

This commit is contained in:
王文璐 2018-05-22 14:01:04 +08:00
parent a9e89ce3f1
commit 4b47c0cb82
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;`);