diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3965ac37cca..ed1fddd2fa0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6203,7 +6203,8 @@ namespace ts { return baseIndexedAccess && baseIndexedAccess !== unknownType ? getBaseConstraint(baseIndexedAccess) : undefined; } if (t.flags & TypeFlags.Conditional) { - return getBaseConstraint(getConstraintOfConditionalType(t)); + const constraint = getConstraintOfConditionalType(t); + return constraint && getBaseConstraint(constraint); } if (t.flags & TypeFlags.Substitution) { return getBaseConstraint((t).substitute); @@ -8237,14 +8238,13 @@ namespace ts { result.checkType = erasedCheckType; result.extendsType = extendsType; result.mapper = mapper; - result.trueTypeMapper = combinedMapper || mapper; result.aliasSymbol = root.aliasSymbol; result.aliasTypeArguments = instantiateTypes(root.aliasTypeArguments, mapper); return result; } function getTrueTypeFromConditionalType(type: ConditionalType) { - return type.resolvedTrueType || (type.resolvedTrueType = instantiateType(getRootTrueType(type.root), type.trueTypeMapper)); + return type.resolvedTrueType || (type.resolvedTrueType = instantiateType(getRootTrueType(type.root), type.mapper)); } function getFalseTypeFromConditionalType(type: ConditionalType) { @@ -8885,10 +8885,6 @@ namespace ts { let result = root.instantiations.get(id); if (!result) { const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments); - // sys.write(`${map(root.outerTypeParameters, t => typeToString(t)).join(",")} ===> ${map(typeArguments, t => typeToString(t)).join(",")}\n`); - // if (every(typeArguments, t => t === wildcardType)) { - // root.instantiations.set(id, wildcardType); - // } result = instantiateConditionalType(root, newMapper); root.instantiations.set(id, result); } @@ -10110,15 +10106,6 @@ namespace ts { } } else if (source.flags & TypeFlags.Conditional) { - if (relation !== definitelyAssignableRelation) { - const constraint = getConstraintOfDistributiveConditionalType(source); - if (constraint) { - if (result = isRelatedTo(constraint, target, reportErrors)) { - errorInfo = saveErrorInfo; - return result; - } - } - } if (target.flags & TypeFlags.Conditional) { if (isTypeIdenticalTo((source).checkType, (target).checkType) && isTypeIdenticalTo((source).extendsType, (target).extendsType)) { @@ -10131,9 +10118,21 @@ namespace ts { } } } - else if (result = isRelatedTo(getDefaultConstraintOfConditionalType(source), target, reportErrors)) { - errorInfo = saveErrorInfo; - return result; + else if (relation !== definitelyAssignableRelation) { + const distributiveConstraint = getConstraintOfDistributiveConditionalType(source); + if (distributiveConstraint) { + if (result = isRelatedTo(distributiveConstraint, target, reportErrors)) { + errorInfo = saveErrorInfo; + return result; + } + } + const defaultConstraint = getDefaultConstraintOfConditionalType(source); + if (defaultConstraint) { + if (result = isRelatedTo(defaultConstraint, target, reportErrors)) { + errorInfo = saveErrorInfo; + return result; + } + } } } else { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2c73182a2c0..cc57d1215f7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3834,8 +3834,6 @@ namespace ts { resolvedFalseType?: Type; /* @internal */ mapper?: TypeMapper; - /* @internal */ - trueTypeMapper?: TypeMapper; } // Type parameter substitution (TypeFlags.Substitution)