TypeScript: Support conditional types syntax (#7404)
Microsoft/TypeScript#21316 and Microsoft/TypeScript#21496
This commit is contained in:
@@ -256,6 +256,28 @@ export function tsPrintUnionOrIntersectionType(node, sep) {
|
||||
});
|
||||
}
|
||||
|
||||
export function TSConditionalType(node) {
|
||||
this.print(node.checkType);
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.space();
|
||||
this.print(node.extendsType);
|
||||
this.space();
|
||||
this.token("?");
|
||||
this.space();
|
||||
this.print(node.trueType);
|
||||
this.space();
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.falseType);
|
||||
}
|
||||
|
||||
export function TSInferType(node) {
|
||||
this.token("infer");
|
||||
this.space();
|
||||
this.print(node.typeParameter);
|
||||
}
|
||||
|
||||
export function TSParenthesizedType(node) {
|
||||
this.token("(");
|
||||
this.print(node.typeAnnotation, node);
|
||||
|
||||
1
packages/babel-generator/test/fixtures/typescript/types-conditional-infer/input.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/types-conditional-infer/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
type Element<T> = T extends (infer U)[] ? U : T;
|
||||
1
packages/babel-generator/test/fixtures/typescript/types-conditional-infer/output.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/types-conditional-infer/output.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
type Element<T> = T extends (infer U)[] ? U : T;
|
||||
1
packages/babel-generator/test/fixtures/typescript/types-conditional/input.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/types-conditional/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
let x: number extends string ? boolean : null;
|
||||
1
packages/babel-generator/test/fixtures/typescript/types-conditional/output.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/typescript/types-conditional/output.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
let x: number extends string ? boolean : null;
|
||||
Reference in New Issue
Block a user