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

@@ -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);
}