Skip to content

Commit 9ccca98

Browse files
committed
Remove reduceType
1 parent e502377 commit 9ccca98

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Diff for: src/compiler/checker.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -22749,7 +22749,8 @@ namespace ts {
2274922749
const inferenceContext = getInferenceInfoForType(target);
2275022750
const constraint = inferenceContext ? getBaseConstraintOfType(inferenceContext.typeParameter) : undefined;
2275122751
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);
2275322754

2275422755
// If the constraint contains `string`, we don't need to look for a more preferred type
2275522756
if (!(allTypeFlags & TypeFlags.String)) {
@@ -22766,7 +22767,7 @@ namespace ts {
2276622767
}
2276722768

2276822769
// 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) =>
2277022771
!(right.flags & allTypeFlags) ? left :
2277122772
left.flags & TypeFlags.String ? left : right.flags & TypeFlags.String ? source :
2277222773
left.flags & TypeFlags.TemplateLiteral ? left : right.flags & TypeFlags.TemplateLiteral && isTypeMatchedByTemplateLiteralType(source, right as TemplateLiteralType) ? source :
@@ -22777,7 +22778,7 @@ namespace ts {
2277722778
left.flags & TypeFlags.NumberLiteral ? left : right.flags & TypeFlags.NumberLiteral && (right as NumberLiteralType).value === +str ? right :
2277822779
left.flags & TypeFlags.BigInt ? left : right.flags & TypeFlags.BigInt ? parseBigIntLiteralType(str) :
2277922780
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 :
2278122782
left.flags & TypeFlags.BooleanLiteral ? left : right.flags & TypeFlags.BooleanLiteral && (right as IntrinsicType).intrinsicName === str ? right :
2278222783
left.flags & TypeFlags.Undefined ? left : right.flags & TypeFlags.Undefined && (right as IntrinsicType).intrinsicName === str ? right :
2278322784
left.flags & TypeFlags.Null ? left : right.flags & TypeFlags.Null && (right as IntrinsicType).intrinsicName === str ? right :
@@ -23800,12 +23801,6 @@ namespace ts {
2380023801
return type.flags & TypeFlags.Union ? forEach((type as UnionType).types, f) : f(type);
2380123802
}
2380223803

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-
2380923804
function someType(type: Type, f: (t: Type) => boolean): boolean {
2381023805
return type.flags & TypeFlags.Union ? some((type as UnionType).types, f) : f(type);
2381123806
}

0 commit comments

Comments
 (0)