8000 Fix formatting of conditional types (#21762) · microsoft/TypeScript@79dde93 · GitHub
[go: up one dir, main page]

< 8000 div data-turbo-body class="logged-out env-production page-responsive" style="word-wrap: break-word;">
Skip to content

Commit 79dde93

Browse files
lankaapuramhegazy
authored andcommitted
Fix formatting of conditional types (#21762)
* Add test for formatting of conditional types * Fix formatting of conditional types
1 parent 384527a commit 79dde93

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/services/formatting/rules.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ namespace ts.formatting {
409409
switch (context.contextNode.kind) {
410410
case SyntaxKind.BinaryExpression:
411411
case SyntaxKind.ConditionalExpression:
412+
case SyntaxKind.ConditionalType:
412413
case SyntaxKind.AsExpression:
413414
case SyntaxKind.ExportSpecifier:
414415
case SyntaxKind.ImportSpecifier:
@@ -461,7 +462,8 @@ namespace ts.formatting {
461462
}
462463

463464
function isConditionalOperatorContext(context: FormattingContext): boolean {
464-
return context.contextNode.kind === SyntaxKind.ConditionalExpression;
465+
return context.contextNode.kind === SyntaxKind.ConditionalExpression ||
466+
context.contextNode.kind === SyntaxKind.ConditionalType;
465467
}
466468

467469
function isSameLineTokenOrBeforeBlockContext(context: FormattingContext): boolean {

tests/cases/fourslash/formattingConditionalOperator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
////var x=true?1:2
44
format.document();
55
goTo.bof();
6-
verify.currentLineContentIs("var x = true ? 1 : 2");;
6+
verify.currentLineContentIs("var x = true ? 1 : 2");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
/////*L1*/type Diff1<T, U> = T extends U?never:T;
4+
/////*L2*/type Diff2<T, U> = T extends U ? never : T;
5+
6+
format.document();
7+
8+
goTo.marker("L1");
9+
verify.currentLineContentIs("type Diff1<T, U> = T extends U ? never : T;");
10+
11+
goTo.marker("L2");
12+
verify.currentLineContentIs("type Diff2<T, U> = T extends U ? never : T;");

0 commit comments

Comments
 (0)
0