mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 19:27:35 -06:00
Fix formatting of conditional types (#21762)
* Add test for formatting of conditional types * Fix formatting of conditional types
This commit is contained in:
parent
384527aa09
commit
79dde93068
@ -409,6 +409,7 @@ namespace ts.formatting {
|
||||
switch (context.contextNode.kind) {
|
||||
case SyntaxKind.BinaryExpression:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
case SyntaxKind.ConditionalType:
|
||||
case SyntaxKind.AsExpression:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
@ -461,7 +462,8 @@ namespace ts.formatting {
|
||||
}
|
||||
|
||||
function isConditionalOperatorContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind === SyntaxKind.ConditionalExpression;
|
||||
return context.contextNode.kind === SyntaxKind.ConditionalExpression ||
|
||||
context.contextNode.kind === SyntaxKind.ConditionalType;
|
||||
}
|
||||
|
||||
function isSameLineTokenOrBeforeBlockContext(context: FormattingContext): boolean {
|
||||
|
||||
@ -3,4 +3,4 @@
|
||||
////var x=true?1:2
|
||||
format.document();
|
||||
goTo.bof();
|
||||
verify.currentLineContentIs("var x = true ? 1 : 2");;
|
||||
verify.currentLineContentIs("var x = true ? 1 : 2");
|
||||
12
tests/cases/fourslash/formattingConditionalTypes.ts
Normal file
12
tests/cases/fourslash/formattingConditionalTypes.ts
Normal file
@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
/////*L1*/type Diff1<T, U> = T extends U?never:T;
|
||||
/////*L2*/type Diff2<T, U> = T extends U ? never : T;
|
||||
|
||||
format.document();
|
||||
|
||||
goTo.marker("L1");
|
||||
verify.currentLineContentIs("type Diff1<T, U> = T extends U ? never : T;");
|
||||
|
||||
goTo.marker("L2");
|
||||
verify.currentLineContentIs("type Diff2<T, U> = T extends U ? never : T;");
|
||||
Loading…
x
Reference in New Issue
Block a user