diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f4e10aac606..4f79b94a520 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6297,7 +6297,8 @@ namespace ts { function getConstraintOfType(type: InstantiableType | UnionOrIntersectionType): Type { return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(type) : type.flags & TypeFlags.IndexedAccess ? getConstraintOfIndexedAccess(type) : - getBaseConstraintOfType(type); + type.flags & TypeFlags.Conditional ? getConstraintOfConditionalType(type) : + getBaseConstraintOfType(type); } function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type { @@ -6314,6 +6315,10 @@ namespace ts { return baseObjectType || baseIndexType ? getIndexedAccessType(baseObjectType || type.objectType, baseIndexType || type.indexType) : undefined; } + function getConstraintOfConditionalType(type: ConditionalType) { + return getUnionType([type.trueType, type.falseType]); + } + function getBaseConstraintOfType(type: Type): Type { if (type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.UnionOrIntersection)) { const constraint = getResolvedBaseConstraint(type); @@ -6393,9 +6398,7 @@ namespace ts { return baseIndexedAccess && baseIndexedAccess !== unknownType ? getBaseConstraint(baseIndexedAccess) : undefined; } if (t.flags & TypeFlags.Conditional) { - const trueBaseType = getBaseConstraint((t).trueType); - const falseBaseType = getBaseConstraint((t).falseType); - return trueBaseType && falseBaseType ? getUnionType([trueBaseType, falseBaseType]) : undefined; + return getBaseConstraint(getConstraintOfConditionalType(t)); } if (t.flags & TypeFlags.Extends) { return booleanType; @@ -9988,12 +9991,9 @@ namespace ts { } } else if (source.flags & TypeFlags.Conditional) { - const constraint = getConstraintOfType(source); - if (constraint) { - if (result = isRelatedTo(constraint, target, reportErrors)) { - errorInfo = saveErrorInfo; - return result; - } + if (result = isRelatedTo(getConstraintOfConditionalType(source), target, reportErrors)) { + errorInfo = saveErrorInfo; + return result; } } else {