mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Merge pull request #12245 from Microsoft/fix12244
Fix string constituent check in checkElementTypeOfArrayOrString
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user