Skip to content

Commit 42ed6aa

Browse files
committed
getTypeFromArrayBindingPattern returns an iterable in ES6
1 parent 8c2cd26 commit 42ed6aa

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2153,7 +2153,16 @@ module ts {
21532153
hasSpreadElement = true;
21542154
}
21552155
});
2156-
return !elementTypes.length ? anyArrayType : hasSpreadElement ? createArrayType(getUnionType(elementTypes)) : createTupleType(elementTypes);
2156+
if (!elementTypes.length) {
2157+
return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
2158+
}
2159+
else if (hasSpreadElement) {
2160+
var unionOfElements = getUnionType(elementTypes);
2161+
return languageVersion >= ScriptTarget.ES6 ? createIterableType(unionOfElements) : createArrayType(unionOfElements);
2162+
}
2163+
2164+
// If the pattern has at least one element, and no rest element, then it should imply a tuple type.
2165+
return createTupleType(elementTypes);
21572166
}
21582167

21592168
// Return the type implied by a binding pattern. This is the type implied purely by the binding pattern itself

0 commit comments

Comments
 (0)