TypeScript: Support conditional types syntax (#7404)

Microsoft/TypeScript#21316 and Microsoft/TypeScript#21496
This commit is contained in:
Andy
2018-02-24 05:56:14 -08:00
committed by Nicolò Ribaudo
parent 960fa66c9e
commit 6f6c8dabba
16 changed files with 587 additions and 1 deletions

View File

@@ -1875,6 +1875,22 @@ Aliases: `TSTypeElement`
---
### tSConditionalType
```javascript
t.tsConditionalType(checkType, extendsType, trueType, falseType)
```
See also `t.isTSConditionalType(node, opts)` and `t.assertTSConditionalType(node, opts)`.
Aliases: `TSType`
- `checkType`: `TSType` (required)
- `extendsType`: `TSType` (required)
- `trueType`: `TSType` (required)
- `falseType`: `TSType` (required)
---
### tSConstructSignatureDeclaration
```javascript
t.tsConstructSignatureDeclaration(typeParameters, parameters, typeAnnotation)
@@ -2074,6 +2090,19 @@ Aliases: `TSType`
---
### tSInferType
```javascript
t.tsInferType(typeParameter)
```
See also `t.isTSInferType(node, opts)` and `t.assertTSInferType(node, opts)`.
Aliases: `TSType`
- `typeParameter`: `TSType` (required)
---
### tSInterfaceBody
```javascript
t.tsInterfaceBody(body)

View File

@@ -801,6 +801,15 @@ export function assertTSIntersectionType(
): void {
assert("TSIntersectionType", node, opts);
}
export function assertTSConditionalType(
node: Object,
opts?: Object = {},
): void {
assert("TSConditionalType", node, opts);
}
export function assertTSInferType(node: Object, opts?: Object = {}): void {
assert("TSInferType", node, opts);
}
export function assertTSParenthesizedType(
node: Object,
opts?: Object = {},

View File

@@ -774,6 +774,16 @@ export function TSIntersectionType(...args: Array<any>): Object {
}
export { TSIntersectionType as tsIntersectionType };
export { TSIntersectionType as tSIntersectionType };
export function TSConditionalType(...args: Array<any>): Object {
return builder("TSConditionalType", ...args);
}
export { TSConditionalType as tsConditionalType };
export { TSConditionalType as tSConditionalType };
export function TSInferType(...args: Array<any>): Object {
return builder("TSInferType", ...args);
}
export { TSInferType as tsInferType };
export { TSInferType as tSInferType };
export function TSParenthesizedType(...args: Array<any>): Object {
return builder("TSParenthesizedType", ...args);
}

View File

@@ -223,6 +223,25 @@ const unionOrIntersection = {
defineType("TSUnionType", unionOrIntersection);
defineType("TSIntersectionType", unionOrIntersection);
defineType("TSConditionalType", {
aliases: ["TSType"],
visitor: ["checkType", "extendsType", "trueType", "falseType"],
fields: {
checkType: validateType("TSType"),
extendsType: validateType("TSType"),
trueType: validateType("TSType"),
falseType: validateType("TSType"),
},
});
defineType("TSInferType", {
aliases: ["TSType"],
visitor: ["typeParameter"],
fields: {
typeParameter: validateType("TSType"),
},
});
defineType("TSParenthesizedType", {
aliases: ["TSType"],
visitor: ["typeAnnotation"],

View File

@@ -608,6 +608,12 @@ export function isTSUnionType(node: Object, opts?: Object): boolean {
export function isTSIntersectionType(node: Object, opts?: Object): boolean {
return is("TSIntersectionType", node, opts);
}
export function isTSConditionalType(node: Object, opts?: Object): boolean {
return is("TSConditionalType", node, opts);
}
export function isTSInferType(node: Object, opts?: Object): boolean {
return is("TSInferType", node, opts);
}
export function isTSParenthesizedType(node: Object, opts?: Object): boolean {
return is("TSParenthesizedType", node, opts);
}