Skip to content

Commit 5f7ecdd

Browse files
committed
Simplify things a bit, only instantiate once
1 parent 85f38ad commit 5f7ecdd

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16024,15 +16024,9 @@ namespace ts {
1602416024
}
1602516025
else if (target.flags & TypeFlags.Conditional) {
1602616026
const c = target as ConditionalType;
16027-
let skipFalse = false;
16028-
let skipTrue = false;
1602916027
// Check if the conditional is always true or always false but still deferred for distribution purposes
16030-
if (!isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType))) {
16031-
skipTrue = true;
16032-
}
16033-
else if (isConditionalTypeAlwaysTrueDisregardingInferTypes(c)) {
16034-
skipFalse = true;
16035-
}
16028+
const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType));
16029+
const skipFalse = !skipTrue && isConditionalTypeAlwaysTrueDisregardingInferTypes(c);
1603616030

1603716031
// Instantiate with a replacement mapper if the conditional is distributive, replacing the check type with a clone of itself,
1603816032
// this way {x: string | number, y: string | number} -> (T extends T ? { x: T, y: T } : never) appropriately _fails_ when
@@ -16048,9 +16042,9 @@ namespace ts {
1604816042

1604916043
// TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't)
1605016044
let localResult: Ternary | undefined;
16051-
if (skipTrue || (localResult = isRelatedTo(source, instantiateType(getTrueTypeFromConditionalType(c), distributionMapper), /*reportErrors*/ false))) {
16045+
if (skipTrue || (localResult = isRelatedTo(source, distributionMapper ? instantiateType(c.root.trueType, distributionMapper) : getTrueTypeFromConditionalType(c), /*reportErrors*/ false))) {
1605216046
if (!skipFalse) {
16053-
localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, instantiateType(getFalseTypeFromConditionalType(c), distributionMapper), /*reportErrors*/ false);
16047+
localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, distributionMapper ? instantiateType(c.root.falseType, distributionMapper) : getFalseTypeFromConditionalType(c), /*reportErrors*/ false);
1605416048
}
1605516049
}
1605616050
if (localResult) {

0 commit comments

Comments
 (0)