@@ -7905,6 +7905,26 @@ module ts {
7905
7905
grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_declaration);
7906
7906
}
7907
7907
7908
+ if (node.expression) {
7909
+ let func = getContainingFunction(node);
7910
+ // If this is correct code, the func should always have a star. After all,
7911
+ // we are in a yield context.
7912
+ // Also, there is no point in doing an assignability check if the function
7913
+ // has no explicit return type, because the return type is directly computed
7914
+ // from the yield expressions.
7915
+ if (func.asteriskToken && func.type) {
7916
+ let signatureElementType = getElementTypeFromIterableIterator(getTypeFromTypeNode(func.type), /*errorNode*/ undefined) || unknownType;
7917
+ let expressionType = checkExpressionCached(node.expression, /*contextualMapper*/ undefined);
7918
+ if (node.asteriskToken) {
7919
+ let expressionElementType = checkIteratedType(expressionType, node.expression);
7920
+ checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, /*headMessage*/ undefined);
7921
+ }
7922
+ else {
7923
+ checkTypeAssignableTo(expressionType, signatureElementType, node.expression, /*headMessage*/ undefined);
7924
+ }
7925
+ }
7926
+ }
7927
+
7908
7928
// Both yield and yield* expressions are any
7909
7929
return anyType;
7910
7930
}
@@ -9480,7 +9500,7 @@ module ts {
9480
9500
}
9481
9501
9482
9502
if (languageVersion >= ScriptTarget.ES6) {
9483
- return checkIteratedType(inputType, errorNode) || anyType ;
9503
+ return checkIteratedType(inputType, errorNode);
9484
9504
}
9485
9505
9486
9506
if (allowStringInput) {
@@ -9509,7 +9529,7 @@ module ts {
9509
9529
checkTypeAssignableTo(iterable, createIterableType(elementType), errorNode);
9510
9530
}
9511
9531
9512
- return elementType;
9532
+ return elementType || anyType ;
9513
9533
}
9514
9534
9515
9535
function getElementTypeFromIterable(iterable: Type, errorNode: Node): Type {
0 commit comments