Skip to content

Commit 4cfb7a5

Browse files
lankaapuramhegazy
authored andcommitted
Fix space issue in mapped type formatting (microsoft#21712)
* Add the test for mapped type formatting issue * Fix inconsistent number of spaces within braces when formatting mapped types
1 parent e0e2f5b commit 4cfb7a5

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/services/formatting/rules.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ namespace ts.formatting {
469469
}
470470

471471
function isBraceWrappedContext(context: FormattingContext): boolean {
472-
return context.contextNode.kind === SyntaxKind.ObjectBindingPattern || isSingleLineBlockContext(context);
472+
return context.contextNode.kind === SyntaxKind.ObjectBindingPattern ||
473+
context.contextNode.kind === SyntaxKind.MappedType ||
474+
isSingleLineBlockContext(context);
473475
}
474476

475477
// This check is done before an open brace in a control construct, a function, or a typescript block declaration
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
/////*x1*/type x1<T> = {[K in keyof T]: number}
4+
/////*x2*/type x2<T> = { [K in keyof T]: number }
5+
/////*x3*/type x3<T> = { [K in keyof T]: number}
6+
/////*x4*/type x4<T> = {[K in keyof T]: number }
7+
/////*x5*/type x5<T> = { [K in keyof T]: number}
8+
/////*x6*/type x6<T> = {[K in keyof T]: number }
9+
/////*x7*/type x7<T> = { [K in keyof T]: number }
10+
/////*x8*/type x8<T> = { [K in keyof T]: number };
11+
////
12+
/////*y1*/type y1 = {foo: number}
13+
/////*y2*/type y2 = { foo: number }
14+
/////*y3*/type y3 = { foo: number}
15+
/////*y4*/type y4 = {foo: number }
16+
/////*y5*/type y5 = { foo: number}
17+
/////*y6*/type y6 = {foo: number }
18+
/////*y7*/type y7 = { foo: number }
19+
/////*y8*/type y8 = { foo: number };
20+
21+
format.document();
22+
for (let index = 1; index < 8; index++) {
23+
goTo.marker(`x${index}`);
24+
verify.currentLineContentIs(`type x${index}<T> = { [K in keyof T]: number }`);
25+
}
26+
27+
goTo.marker(`x8`);
28+
verify.currentLineContentIs(`type x8<T> = { [K in keyof T]: number };`);
29+
30+
for (let index = 1; index < 8; index++) {
31+
goTo.marker(`y${index}`);
32+
verify.currentLineContentIs(`type y${index} = { foo: number }`);
33+
}
34+
35+
goTo.marker(`y8`);
36+
verify.currentLineContentIs(`type y8 = { foo: number };`);

0 commit comments

Comments
 (0)