Merge pull request #12245 from Microsoft/fix12244

Fix string constituent check in checkElementTypeOfArrayOrString
This commit is contained in:
Ron Buckton
2016-11-14 15:27:45 -08:00
committed by GitHub
25 changed files with 73243 additions and 58274 deletions

View File

@@ -17257,11 +17257,15 @@ namespace ts {
function checkElementTypeOfArrayOrString(arrayOrStringType: Type, errorNode: Node): Type {
Debug.assert(languageVersion < ScriptTarget.ES2015);
// After we remove all types that are StringLike, we will know if there was a string constituent
// based on whether the remaining type is the same as the initial type.
let arrayType = arrayOrStringType;
if (arrayOrStringType.flags & TypeFlags.Union) {
arrayType = getUnionType(filter((arrayOrStringType as UnionType).types, t => !(t.flags & TypeFlags.StringLike)), /*subtypeReduction*/ true);
// After we remove all types that are StringLike, we will know if there was a string constituent
// based on whether the result of filter is a new array.
const arrayTypes = (arrayOrStringType as UnionType).types;
const filteredTypes = filter(arrayTypes, t => !(t.flags & TypeFlags.StringLike));
if (filteredTypes !== arrayTypes) {
arrayType = getUnionType(filteredTypes, /*subtypeReduction*/ true);
}
}
else if (arrayOrStringType.flags & TypeFlags.StringLike) {
arrayType = neverType;