diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index a75781b8da0e4..4c93d7816e75d 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -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; diff --git a/tests/cases/fourslash/formatLiteralTypeInUnionOrIntersectionType.ts b/tests/cases/fourslash/formatLiteralTypeInUnionOrIntersectionType.ts new file mode 100644 index 0000000000000..81bba56adf20f --- /dev/null +++ b/tests/cases/fourslash/formatLiteralTypeInUnionOrIntersectionType.ts @@ -0,0 +1,37 @@ +/// + +//// 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;`);