diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index f6a9dee4cfe..d8c94e8c772 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -469,7 +469,9 @@ namespace ts.formatting { } function isBraceWrappedContext(context: FormattingContext): boolean { - return context.contextNode.kind === SyntaxKind.ObjectBindingPattern || isSingleLineBlockContext(context); + return context.contextNode.kind === SyntaxKind.ObjectBindingPattern || + context.contextNode.kind === SyntaxKind.MappedType || + isSingleLineBlockContext(context); } // This check is done before an open brace in a control construct, a function, or a typescript block declaration diff --git a/tests/cases/fourslash/formattingMultipleMappedType.ts b/tests/cases/fourslash/formattingMultipleMappedType.ts new file mode 100644 index 00000000000..1ebfd3144d7 --- /dev/null +++ b/tests/cases/fourslash/formattingMultipleMappedType.ts @@ -0,0 +1,36 @@ +/// + +/////*x1*/type x1 = {[K in keyof T]: number} +/////*x2*/type x2 = { [K in keyof T]: number } +/////*x3*/type x3 = { [K in keyof T]: number} +/////*x4*/type x4 = {[K in keyof T]: number } +/////*x5*/type x5 = { [K in keyof T]: number} +/////*x6*/type x6 = {[K in keyof T]: number } +/////*x7*/type x7 = { [K in keyof T]: number } +/////*x8*/type x8 = { [K in keyof T]: number }; +//// +/////*y1*/type y1 = {foo: number} +/////*y2*/type y2 = { foo: number } +/////*y3*/type y3 = { foo: number} +/////*y4*/type y4 = {foo: number } +/////*y5*/type y5 = { foo: number} +/////*y6*/type y6 = {foo: number } +/////*y7*/type y7 = { foo: number } +/////*y8*/type y8 = { foo: number }; + +format.document(); +for (let index = 1; index < 8; index++) { + goTo.marker(`x${index}`); + verify.currentLineContentIs(`type x${index} = { [K in keyof T]: number }`); +} + +goTo.marker(`x8`); +verify.currentLineContentIs(`type x8 = { [K in keyof T]: number };`); + +for (let index = 1; index < 8; index++) { + goTo.marker(`y${index}`); + verify.currentLineContentIs(`type y${index} = { foo: number }`); +} + +goTo.marker(`y8`); +verify.currentLineContentIs(`type y8 = { foo: number };`); \ No newline at end of file