@@ -5850,7 +5850,7 @@ module ts {
5850
5850
let index = indexOf(arrayLiteral.elements, node);
5851
5851
return getTypeOfPropertyOfContextualType(type, "" + index)
5852
5852
|| getIndexTypeOfContextualType(type, IndexKind.Number)
5853
- || (languageVersion >= ScriptTarget.ES6 ? checkIteratedType (type, /*expressionForError*/ undefined) : undefined);
5853
+ || (languageVersion >= ScriptTarget.ES6 ? getIteratedType (type, /*expressionForError*/ undefined) : undefined);
5854
5854
}
5855
5855
return undefined;
5856
5856
}
@@ -6037,7 +6037,7 @@ module ts {
6037
6037
// if there is no index type / iterated type.
6038
6038
let restArrayType = checkExpression((<SpreadElementExpression>e).expression, contextualMapper);
6039
6039
let restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) ||
6040
- (languageVersion >= ScriptTarget.ES6 ? checkIteratedType (restArrayType, /*expressionForError*/ undefined) : undefined);
6040
+ (languageVersion >= ScriptTarget.ES6 ? getIteratedType (restArrayType, /*expressionForError*/ undefined) : undefined);
6041
6041
6042
6042
if (restElementType) {
6043
6043
elementTypes.push(restElementType);
@@ -9469,7 +9469,6 @@ module ts {
9469
9469
* When errorNode is undefined, it means we should not report any errors.
9470
9470
*/
9471
9471
function checkIteratedType(iterable: Type, errorNode: Node): Type {
9472
- Debug.assert(languageVersion >= ScriptTarget.ES6);
9473
9472
let iteratedType = getIteratedType(iterable, errorNode);
9474
9473
// Now even though we have extracted the iteratedType, we will have to validate that the type
9475
9474
// passed in is actually an Iterable.
@@ -9478,90 +9477,91 @@ module ts {
9478
9477
}
9479
9478
9480
9479
return iteratedType;
9480
+ }
9481
9481
9482
- function getIteratedType(iterable: Type, errorNode: Node) {
9483
- // We want to treat type as an iterable, and get the type it is an iterable of. The iterable
9484
- // must have the following structure (annotated with the names of the variables below):
9485
- //
9486
- // { // iterable
9487
- // [Symbol.iterator]: { // iteratorFunction
9488
- // (): { // iterator
9489
- // next: { // iteratorNextFunction
9490
- // (): { // iteratorNextResult
9491
- // value: T // iteratorNextValue
9492
- // }
9493
- // }
9494
- // }
9495
- // }
9496
- // }
9497
- //
9498
- // T is the type we are after. At every level that involves analyzing return types
9499
- // of signatures, we union the return types of all the signatures.
9500
- //
9501
- // Another thing to note is that at any step of this process, we could run into a dead end,
9502
- // meaning either the property is missing, or we run into the anyType. If either of these things
9503
- // happens, we return undefined to signal that we could not find the iterated type. If a property
9504
- // is missing, and the previous step did not result in 'any', then we also give an error if the
9505
- // caller requested it. Then the caller can decide what to do in the case where there is no iterated
9506
- // type. This is different from returning anyType, because that would signify that we have matched the
9507
- // whole pattern and that T (above) is 'any'.
9508
-
9509
- if (allConstituentTypesHaveKind(iterable, TypeFlags.Any)) {
9510
- return undefined;
9511
- }
9482
+ function getIteratedType(iterable: Type, errorNode: Node) {
9483
+ Debug.assert(languageVersion >= ScriptTarget.ES6);
9484
+ // We want to treat type as an iterable, and get the type it is an iterable of. The iterable
9485
+ // must have the following structure (annotated with the names of the variables below):
9486
+ //
9487
+ // { // iterable
9488
+ // [Symbol.iterator]: { // iteratorFunction
9489
+ // (): { // iterator
9490
+ // next: { // iteratorNextFunction
9491
+ // (): { // iteratorNextResult
9492
+ // value: T // iteratorNextValue
9493
+ // }
9494
+ // }
9495
+ // }
9496
+ // }
9497
+ // }
9498
+ //
9499
+ // T is the type we are after. At every level that involves analyzing return types
9500
+ // of signatures, we union the return types of all the signatures.
9501
+ //
9502
+ // Another thing to note is that at any step of this process, we could run into a dead end,
9503
+ // meaning either the property is missing, or we run into the anyType. If either of these things
9504
+ // happens, we return undefined to signal that we could not find the iterated type. If a property
9505
+ // is missing, and the previous step did not result in 'any', then we also give an error if the
9506
+ // caller requested it. Then the caller can decide what to do in the case where there is no iterated
9507
+ // type. This is different from returning anyType, because that would signify that we have matched the
9508
+ // whole pattern and that T (above) is 'any'.
9509
+
9510
+ if (allConstituentTypesHaveKind(iterable, TypeFlags.Any)) {
9511
+ return undefined;
9512
+ }
9512
9513
9513
- // As an optimization, if the type is instantiated directly using the globalIterableType (Iterable<number>),
9514
- // then just grab its type argument.
9515
- if ((iterable.flags & TypeFlags.Reference) && (<GenericType>iterable).target === globalIterableType) {
9516
- return (<GenericType>iterable).typeArguments[0];
9517
- }
9514
+ // As an optimization, if the type is instantiated directly using the globalIterableType (Iterable<number>),
9515
+ // then just grab its type argument.
9516
+ if ((iterable.flags & TypeFlags.Reference) && (<GenericType>iterable).target === globalIterableType) {
9517
+ return (<GenericType>iterable).typeArguments[0];
9518
+ }
9518
9519
9519
- let iteratorFunction = getTypeOfPropertyOfType(iterable, getPropertyNameForKnownSymbolName("iterator"));
9520
- if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, TypeFlags.Any)) {
9521
- return undefined;
9522
- }
9520
+ let iteratorFunction = getTypeOfPropertyOfType(iterable, getPropertyNameForKnownSymbolName("iterator"));
9521
+ if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, TypeFlags.Any)) {
9522
+ return undefined;
9523
+ }
9523
9524
9524
- let iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, SignatureKind.Call) : emptyArray;
9525
- if (iteratorFunctionSignatures.length === 0) {
9526
- if (errorNode) {
9527
- error(errorNode, Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
9528
- }
9529
- return undefined;
9525
+ let iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, SignatureKind.Call) : emptyArray;
9526
+ if (iteratorFunctionSignatures.length === 0) {
9527
+ if (errorNode) {
9528
+ error(errorNode, Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
9530
9529
}
9530
+ return undefined;
9531
+ }
9531
9532
9532
- let iterator = getUnionType(map(iteratorFunctionSignatures, getReturnTypeOfSignature));
9533
- if (allConstituentTypesHaveKind(iterator, TypeFlags.Any)) {
9534
- return undefined;
9535
- }
9533
+ let iterator = getUnionType(map(iteratorFunctionSignatures, getReturnTypeOfSignature));
9534
+ if (allConstituentTypesHaveKind(iterator, TypeFlags.Any)) {
9535
+ return undefined;
9536
+ }
9536
9537
9537
- let iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next");
9538
- if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, TypeFlags.Any)) {
9539
- return undefined;
9540
- }
9538
+ let iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next");
9539
+ if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, TypeFlags.Any)) {
9540
+ return undefined;
9541
+ }
9541
9542
9542
- let iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, SignatureKind.Call) : emptyArray;
9543
- if (iteratorNextFunctionSignatures.length === 0) {
9544
- if (errorNode) {
9545
- error(errorNode, Diagnostics.An_iterator_must_have_a_next_method);
9546
- }
9547
- return undefined;
9543
+ let iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, SignatureKind.Call) : emptyArray;
9544
+ if (iteratorNextFunctionSignatures.length === 0) {
9545
+ if (errorNode) {
9546
+ error(errorNode, Diagnostics.An_iterator_must_have_a_next_method);
9548
9547
}
9548
+ return undefined;
9549
+ }
9549
9550
9550
- let iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature));
9551
- if (allConstituentTypesHaveKind(iteratorNextResult, TypeFlags.Any)) {
9552
- return undefined;
9553
- }
9551
+ let iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature));
9552
+ if (allConstituentTypesHaveKind(iteratorNextResult, TypeFlags.Any)) {
9553
+ return undefined;
9554
+ }
9554
9555
9555
- let iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
9556
- if (!iteratorNextValue) {
9557
- if (errorNode) {
9558
- error(errorNode, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
9559
- }
9560
- return undefined;
9556
+ let iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
9557
+ if (!iteratorNextValue) {
9558
+ if (errorNode) {
9559
+ error(errorNode, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
9561
9560
}
9562
-
9563
- return iteratorNextValue;
9561
+ return undefined;
9564
9562
}
9563
+
9564
+ return iteratorNextValue;
9565
9565
}
9566
9566
9567
9567
/**
0 commit comments