mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Add contextual typing for await operand
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user