@@ -15315,13 +15315,6 @@ namespace ts {
15315
15315
return type[cache] = type;
15316
15316
}
15317
15317
15318
- function isConditionalTypeAlwaysTrueDisregardingInferTypes(type: ConditionalType) {
15319
- const extendsInferParamMapper = type.root.inferTypeParameters && createTypeMapper(type.root.inferTypeParameters, map(type.root.inferTypeParameters, () => wildcardType));
15320
- const checkType = type.checkType;
15321
- const extendsType = type.extendsType;
15322
- return isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(instantiateType(extendsType, extendsInferParamMapper)));
15323
- }
15324
-
15325
15318
function getSimplifiedConditionalType(type: ConditionalType, writing: boolean) {
15326
15319
const checkType = type.checkType;
15327
15320
const extendsType = type.extendsType;
@@ -19030,35 +19023,15 @@ namespace ts {
19030
19023
resetErrorInfo(saveErrorInfo);
19031
19024
return Ternary.Maybe;
19032
19025
}
19033
- const c = target as ConditionalType;
19034
- // Check if the conditional is always true or always false but still deferred for distribution purposes
19035
- const skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType));
19036
- const skipFalse = !skipTrue && isConditionalTypeAlwaysTrueDisregardingInferTypes(c);
19037
-
19038
- // Instantiate with a replacement mapper if the conditional is distributive, replacing the check type with a clone of itself,
19039
- // this way {x: string | number, y: string | number} -> (T extends T ? { x: T, y: T } : never) appropriately _fails_ when
19040
- // T = string | number (since that will end up distributing and producing `{x: string, y: string} | {x: number, y: number}`,
19041
- // to which `{x: string | number, y: string | number}` isn't assignable)
19042
- let distributionMapper: TypeMapper | undefined;
19043
- const checkVar = getActualTypeVariable(c.root.checkType);
19044
- if (c.root.isDistributive && checkVar.flags & TypeFlags.TypeParameter) {
19045
- const newParam = cloneTypeParameter(checkVar);
19046
- distributionMapper = prependTypeMapping(checkVar, newParam, c.mapper);
19047
- newParam.mapper = distributionMapper;
19048
- }
19049
-
19050
- // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't)
19051
- const expanding = isDeeplyNestedType(target, targetStack, targetDepth);
19052
- let localResult: Ternary | undefined = expanding ? Ternary.Maybe : undefined;
19053
- if (skipTrue || expanding || (localResult = isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.trueType), distributionMapper) : getTrueTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false))) {
19054
- if (!skipFalse && !expanding) {
19055
- localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, distributionMapper ? instantiateType(getTypeFromTypeNode(c.root.node.falseType), distributionMapper) : getFalseTypeFromConditionalType(c), RecursionFlags.Target, /*reportErrors*/ false);
19026
+ if (!(target as ConditionalType).root.inferTypeParameters) {
19027
+ if (result = isRelatedTo(source, getTrueTypeFromConditionalType(target as ConditionalType), RecursionFlags.Target, /*reportErrors*/ false)) {
19028
+ result &= isRelatedTo(source, getFalseTypeFromConditionalType(target as ConditionalType), RecursionFlags.Target, /*reportErrors*/ false);
19029
+ if (result) {
19030
+ resetErrorInfo(saveErrorInfo);
19031
+ return result;
19032
+ }
19056
19033
}
19057
19034
}
19058
- if (localResult) {
19059
- resetErrorInfo(saveErrorInfo);
19060
- return localResult;
19061
- }
19062
19035
}
19063
19036
else if (target.flags & TypeFlags.TemplateLiteral) {
19064
19037
if (source.flags & TypeFlags.TemplateLiteral) {
0 commit comments