@@ -22749,7 +22749,8 @@ namespace ts {
22749
22749
const inferenceContext = getInferenceInfoForType(target);
22750
22750
const constraint = inferenceContext ? getBaseConstraintOfType(inferenceContext.typeParameter) : undefined;
22751
22751
if (constraint && !isTypeAny(constraint)) {
22752
- let allTypeFlags = reduceType(constraint, (flags, t) => flags | t.flags, 0 as TypeFlags);
22752
+ const constraintTypes = constraint.flags & TypeFlags.Union ? (constraint as UnionType).types : [constraint];
22753
+ let allTypeFlags: TypeFlags = reduceLeft(constraintTypes, (flags, t) => flags | t.flags, 0 as TypeFlags);
22753
22754
22754
22755
// If the constraint contains `string`, we don't need to look for a more preferred type
22755
22756
if (!(allTypeFlags & TypeFlags.String)) {
@@ -22766,7 +22767,7 @@ namespace ts {
22766
22767
}
22767
22768
22768
22769
// for each type in the constraint, find the highest priority matching type
22769
- const matchingType = reduceType(constraint , (left, right) =>
22770
+ const matchingType = reduceLeft(constraintTypes , (left, right) =>
22770
22771
!(right.flags & allTypeFlags) ? left :
22771
22772
left.flags & TypeFlags.String ? left : right.flags & TypeFlags.String ? source :
22772
22773
left.flags & TypeFlags.TemplateLiteral ? left : right.flags & TypeFlags.TemplateLiteral && isTypeMatchedByTemplateLiteralType(source, right as TemplateLiteralType) ? source :
@@ -22777,7 +22778,7 @@ namespace ts {
22777
22778
left.flags & TypeFlags.NumberLiteral ? left : right.flags & TypeFlags.NumberLiteral && (right as NumberLiteralType).value === +str ? right :
22778
22779
left.flags & TypeFlags.BigInt ? left : right.flags & TypeFlags.BigInt ? parseBigIntLiteralType(str) :
22779
22780
left.flags & TypeFlags.BigIntLiteral ? left : right.flags & TypeFlags.BigIntLiteral && pseudoBigIntToString((right as BigIntLiteralType).value) === str ? right :
22780
- left.flags & TypeFlags.Boolean ? left : right.flags & TypeFlags.Boolean ? str === "true" ? trueType : falseType :
22781
+ left.flags & TypeFlags.Boolean ? left : right.flags & TypeFlags.Boolean ? str === "true" ? trueType : str === "false" ? falseType : booleanType :
22781
22782
left.flags & TypeFlags.BooleanLiteral ? left : right.flags & TypeFlags.BooleanLiteral && (right as IntrinsicType).intrinsicName === str ? right :
22782
22783
left.flags & TypeFlags.Undefined ? left : right.flags & TypeFlags.Undefined && (right as IntrinsicType).intrinsicName === str ? right :
22783
22784
left.flags & TypeFlags.Null ? left : right.flags & TypeFlags.Null && (right as IntrinsicType).intrinsicName === str ? right :
@@ -23800,12 +23801,6 @@ namespace ts {
23800
23801
return type.flags & TypeFlags.Union ? forEach((type as UnionType).types, f) : f(type);
23801
23802
}
23802
23803
23803
- function reduceType<T>(type: Type, f: (memo: T, t: Type) => T | undefined, initial: T): T;
23804
- function reduceType<T>(type: Type, f: (memo: T | undefined, t: Type) => T | undefined): T | undefined;
23805
- function reduceType<T>(type: Type, f: (memo: T | undefined, t: Type) => T | undefined, initial?: T | undefined): T | undefined {
23806
- return type.flags & TypeFlags.Union ? reduceLeft((type as UnionType).types, f, initial) : f(initial, type);
23807
- }
23808
-
23809
23804
function someType(type: Type, f: (t: Type) => boolean): boolean {
23810
23805
return type.flags & TypeFlags.Union ? some((type as UnionType).types, f) : f(type);
23811
23806
}
0 commit comments