Skip to content

Commit

Permalink
Simplify things a bit, only instantiate once
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Apr 1, 2020
1 parent 85f38ad commit 5f7ecdd
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16024,15 +16024,9 @@ namespace ts {
}
else if (target.flags & TypeFlags.Conditional) {
const c = target as ConditionalType;
let skipFalse = false;
let skipTrue = false;
// Check if the conditional is always true or always false but still deferred for distribution purposes
if (!isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType))) {
skipTrue = true;
}
else if (isConditionalTypeAlwaysTrueDisregardingInferTypes(c)) {
skipFalse = true;
}
const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType));
const skipFalse = !skipTrue && isConditionalTypeAlwaysTrueDisregardingInferTypes(c);

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

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

0 comments on commit 5f7ecdd

Please sign in to comment.