@@ -9725,42 +9725,43 @@ module ts {
9725
9725
9726
9726
return elementType || anyType;
9727
9727
}
9728
-
9729
- function getElementTypeOfIterable(iterable: Type, errorNode: Node): Type {
9730
- // We want to treat type as an iterable, and get the type it is an iterable of. The iterable
9731
- // must have the following structure (annotated with the names of the variables below):
9732
- //
9733
- // { // iterable
9734
- // [Symbol.iterator]: { // iteratorFunction
9735
- // (): Iterator<T>
9736
- // }
9737
- // }
9738
- //
9739
- // T is the type we are after. At every level that involves analyzing return types
9740
- // of signatures, we union the return types of all the signatures.
9741
- //
9742
- // Another thing to note is that at any step of this process, we could run into a dead end,
9743
- // meaning either the property is missing, or we run into the anyType. If either of these things
9744
- // happens, we return undefined to signal that we could not find the iterated type. If a property
9745
- // is missing, and the previous step did not result in 'any', then we also give an error if the
9746
- // caller requested it. Then the caller can decide what to do in the case where there is no iterated
9747
- // type. This is different from returning anyType, because that would signify that we have matched the
9748
- // whole pattern and that T (above) is 'any'.
9749
-
9750
- if (allConstituentTypesHaveKind(iterable, TypeFlags.Any)) {
9728
+
9729
+ /**
9730
+ * We want to treat type as an iterable, and get the type it is an iterable of. The iterable
9731
+ * must have the following structure (annotated with the names of the variables below):
9732
+ *
9733
+ * { // iterable
9734
+ * [Symbol.iterator]: { // iteratorFunction
9735
+ * (): Iterator<T>
9736
+ * }
9737
+ * }
9738
+ *
9739
+ * T is the type we are after. At every level that involves analyzing return types
9740
+ * of signatures, we union the return types of all the signatures.
9741
+ *
9742
+ * Another thing to note is that at any step of this process, we could run into a dead end,
9743
+ * meaning either the property is missing, or we run into the anyType. If either of these things
9744
+ * happens, we return undefined to signal that we could not find the iterated type. If a property
9745
+ * is missing, and the previous step did not result in 'any', then we also give an error if the
9746
+ * caller requested it. Then the caller can decide what to do in the case where there is no iterated
9747
+ * type. This is different from returning anyType, because that would signify that we have matched the
9748
+ * whole pattern and that T (above) is 'any'.
9749
+ */
9750
+ function getElementTypeOfIterable(type: Type, errorNode: Node): Type {
9751
+ if (type.flags & TypeFlags.Any) {
9751
9752
return undefined;
9752
9753
}
9753
9754
9754
- let typeAsIterable = <IterableOrIteratorType>iterable ;
9755
+ let typeAsIterable = <IterableOrIteratorType>type ;
9755
9756
if (!typeAsIterable.iterableElementType) {
9756
9757
// As an optimization, if the type is instantiated directly using the globalIterableType (Iterable<number>),
9757
9758
// then just grab its type argument.
9758
- if ((iterable .flags & TypeFlags.Reference) && (<GenericType>iterable ).target === globalIterableType) {
9759
- typeAsIterable.iterableElementType = (<GenericType>iterable ).typeArguments[0];
9759
+ if ((type .flags & TypeFlags.Reference) && (<GenericType>type ).target === globalIterableType) {
9760
+ typeAsIterable.iterableElementType = (<GenericType>type ).typeArguments[0];
9760
9761
}
9761
9762
else {
9762
- let iteratorFunction = getTypeOfPropertyOfType(iterable , getPropertyNameForKnownSymbolName("iterator"));
9763
- if (iteratorFunction && allConstituentTypesHaveKind( iteratorFunction, TypeFlags.Any) ) {
9763
+ let iteratorFunction = getTypeOfPropertyOfType(type , getPropertyNameForKnownSymbolName("iterator"));
9764
+ if (iteratorFunction && iteratorFunction.flags & TypeFlags.Any) {
9764
9765
return undefined;
9765
9766
}
9766
9767
@@ -9779,32 +9780,34 @@ module ts {
9779
9780
return typeAsIterable.iterableElementType;
9780
9781
}
9781
9782
9782
- function getElementTypeOfIterator(iterator: Type, errorNode: Node): Type {
9783
- // This function has very similar logic as getElementTypeOfIterable, except that it operates on
9784
- // Iterators instead of Iterables. Here is the structure:
9785
- //
9786
- // { // iterator
9787
- // next: { // iteratorNextFunction
9788
- // (): { // iteratorNextResult
9789
- // value: T // iteratorNextValue
9790
- // }
9791
- // }
9792
- // }
9793
- //
9794
- if (allConstituentTypesHaveKind(iterator, TypeFlags.Any)) {
9783
+ /**
9784
+ * This function has very similar logic as getElementTypeOfIterable, except that it operates on
9785
+ * Iterators instead of Iterables. Here is the structure:
9786
+ *
9787
+ * { // iterator
9788
+ * next: { // iteratorNextFunction
9789
+ * (): { // iteratorNextResult
9790
+ * value: T // iteratorNextValue
9791
+ * }
9792
+ * }
9793
+ * }
9794
+ *
9795
+ */
9796
+ function getElementTypeOfIterator(type: Type, errorNode: Node): Type {
9797
+ if (type.flags & TypeFlags.Any) {
9795
9798
return undefined;
9796
9799
}
9797
9800
9798
- let typeAsIterator = <IterableOrIteratorType>iterator ;
9801
+ let typeAsIterator = <IterableOrIteratorType>type ;
9799
9802
if (!typeAsIterator.iteratorElementType) {
9800
9803
// As an optimization, if the type is instantiated directly using the globalIteratorType (Iterator<number>),
9801
9804
// then just grab its type argument.
9802
- if ((iterator .flags & TypeFlags.Reference) && (<GenericType>iterator ).target === globalIteratorType) {
9803
- typeAsIterator.iteratorElementType = (<GenericType>iterator ).typeArguments[0];
9805
+ if ((type .flags & TypeFlags.Reference) && (<GenericType>type ).target === globalIteratorType) {
9806
+ typeAsIterator.iteratorElementType = (<GenericType>type ).typeArguments[0];
9804
9807
}
9805
9808
else {
9806
- let iteratorNextFunction = getTypeOfPropertyOfType(iterator , "next");
9807
- if (iteratorNextFunction && allConstituentTypesHaveKind( iteratorNextFunction, TypeFlags.Any) ) {
9809
+ let iteratorNextFunction = getTypeOfPropertyOfType(type , "next");
9810
+ if (iteratorNextFunction && iteratorNextFunction.flags & TypeFlags.Any) {
9808
9811
return undefined;
9809
9812
}
9810
9813
@@ -9817,7 +9820,7 @@ module ts {
9817
9820
}
9818
9821
9819
9822
let iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature));
9820
- if (allConstituentTypesHaveKind( iteratorNextResult, TypeFlags.Any) ) {
9823
+ if (iteratorNextResult.flags & TypeFlags.Any) {
9821
9824
return undefined;
9822
9825
}
9823
9826
@@ -9836,19 +9839,19 @@ module ts {
9836
9839
return typeAsIterator.iteratorElementType;
9837
9840
}
9838
9841
9839
- function getElementTypeOfIterableIterator(iterableIterator : Type): Type {
9840
- if (allConstituentTypesHaveKind(iterableIterator, TypeFlags.Any) ) {
9842
+ function getElementTypeOfIterableIterator(type : Type): Type {
9843
+ if (type.flags & TypeFlags.Any) {
9841
9844
return undefined;
9842
9845
}
9843
9846
9844
9847
// As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator<number>),
9845
9848
// then just grab its type argument.
9846
- if ((iterableIterator .flags & TypeFlags.Reference) && (<GenericType>iterableIterator ).target === globalIterableIteratorType) {
9847
- return (<GenericType>iterableIterator ).typeArguments[0];
9849
+ if ((type .flags & TypeFlags.Reference) && (<GenericType>type ).target === globalIterableIteratorType) {
9850
+ return (<GenericType>type ).typeArguments[0];
9848
9851
}
9849
9852
9850
- return getElementTypeOfIterable(iterableIterator , /*errorNode*/ undefined) ||
9851
- getElementTypeOfIterator(iterableIterator , /*errorNode*/ undefined);
9853
+ return getElementTypeOfIterable(type , /*errorNode*/ undefined) ||
9854
+ getElementTypeOfIterator(type , /*errorNode*/ undefined);
9852
9855
}
9853
9856
9854
9857
/**
0 commit comments