Add contextual typing for await operand

This commit is contained in:
Ron Buckton
2018-09-21 10:17:18 -07:00
parent 80dba4d63b
commit 63adc5fb40
4 changed files with 77 additions and 1 deletions

View File

@@ -16409,6 +16409,15 @@ namespace ts {
return undefined;
}
function getContextualTypeForAwaitOperand(node: AwaitExpression): Type | undefined {
const contextualType = getContextualType(node);
if (contextualType) {
const contextualAwaitedType = getAwaitedType(contextualType);
return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]);
}
return undefined;
}
function getContextualTypeForYieldOperand(node: YieldExpression): Type | undefined {
const func = getContainingFunction(node);
if (func) {
@@ -16770,7 +16779,9 @@ namespace ts {
return getContextualTypeForReturnExpression(node);
case SyntaxKind.YieldExpression:
return getContextualTypeForYieldOperand(<YieldExpression>parent);
case SyntaxKind.CallExpression:
case SyntaxKind.AwaitExpression:
return getContextualTypeForAwaitOperand(<AwaitExpression>parent);
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
return getContextualTypeForArgument(<CallExpression | NewExpression>parent, node);
case SyntaxKind.TypeAssertionExpression: