Skip to content

Commit aa4138d

Browse files
committed
Remove last changes regarding conditional type assignability
1 parent 4336dd5 commit aa4138d

File tree

1 file changed

+2
-37
lines changed

1 file changed

+2
-37
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15355,40 +15355,6 @@ namespace ts {
1535515355
}
1535615356
}
1535715357
}
15358-
else if (target.flags & TypeFlags.Conditional) {
15359-
const c = target as ConditionalType;
15360-
let skipFalse = false;
15361-
let skipTrue = false;
15362-
// Check if the conditional is always true or always false but still deferred for distribution purposes
15363-
if (!isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType))) {
15364-
skipTrue = true;
15365-
}
15366-
else if (isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType))) {
15367-
skipFalse = true;
15368-
}
15369-
// Instantiate with a replacement mapper if the conditional is distributive, replacing the check type with a clone of itself,
15370-
// this way {x: string | number, y: string | number} -> (T extends T ? { x: T, y: T } : never) appropriately _fails_ when
15371-
// T = string | number (since that will end up distributing and producing `{x: string, y: string} | {x: number, y: number}`,
15372-
// to which `{x: string | number, y: string | number}` isn't assignable)
15373-
let distributionMapper: TypeMapper | undefined;
15374-
const checkVar = getActualTypeVariable(c.root.checkType);
15375-
if (c.root.isDistributive && checkVar.flags & TypeFlags.TypeParameter) {
15376-
const newParam = cloneTypeParameter(checkVar);
15377-
distributionMapper = createReplacementMapper(checkVar, newParam, c.mapper || identityMapper);
15378-
newParam.mapper = distributionMapper;
15379-
}
15380-
// TODO: Find a nice way to include potential conditional type breakdowns in error output, if those seems good (they usually don't)
15381-
let localResult: Ternary | undefined;
15382-
if (skipTrue || (localResult = isRelatedTo(source, instantiateType(getTrueTypeFromConditionalType(c), distributionMapper), /*reportErrors*/ false))) {
15383-
if (!skipFalse) {
15384-
localResult = (localResult || Ternary.Maybe) & isRelatedTo(source, instantiateType(getFalseTypeFromConditionalType(c), distributionMapper), /*reportErrors*/ false);
15385-
}
15386-
}
15387-
if (localResult) {
15388-
errorInfo = saveErrorInfo;
15389-
return localResult;
15390-
}
15391-
}
1539215358

1539315359
if (source.flags & TypeFlags.TypeVariable) {
1539415360
if (source.flags & TypeFlags.IndexedAccess && target.flags & TypeFlags.IndexedAccess) {
@@ -15444,9 +15410,8 @@ namespace ts {
1544415410
sourceExtends = instantiateType(sourceExtends, ctx.mapper);
1544515411
mapper = ctx.mapper;
1544615412
}
15447-
if (isRelatedTo(sourceExtends, (<ConditionalType>target).extendsType) &&
15448-
isRelatedTo((<ConditionalType>target).extendsType, sourceExtends) &&
15449-
(isRelatedTo((<ConditionalType>source).checkType, (<ConditionalType>target).checkType) || isRelatedTo((<ConditionalType>target).checkType, (<ConditionalType>source).checkType))) {
15413+
if (isTypeIdenticalTo(sourceExtends, (<ConditionalType>target).extendsType) &&
15414+
(isRelatedTo((<ConditionalType>source).checkType, (<ConditionalType>target).checkType) || isRelatedTo((<ConditionalType>target).checkType, (<ConditionalType>source).checkType))) {
1545015415
if (result = isRelatedTo(instantiateType(getTrueTypeFromConditionalType(<ConditionalType>source), mapper), getTrueTypeFromConditionalType(<ConditionalType>target), reportErrors)) {
1545115416
result &= isRelatedTo(getFalseTypeFromConditionalType(<ConditionalType>source), getFalseTypeFromConditionalType(<ConditionalType>target), reportErrors);
1545215417
}

0 commit comments

Comments
 (0)