@@ -11823,11 +11823,6 @@ namespace ts {
11823
11823
return hasNonCircularBaseConstraint(type) ? getConstraintFromConditionalType(type) : undefined;
11824
11824
}
11825
11825
11826
- function isUnionContainingMultipleObjectLikeTypes(type: Type) {
11827
- return !!(type.flags & TypeFlags.Union) &&
11828
- countWhere((type as UnionType).types, t => !!(t.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags.Substitution))) >= 2;
11829
- }
11830
-
11831
11826
function getEffectiveConstraintOfIntersection(types: readonly Type[], targetIsUnion: boolean) {
11832
11827
let constraints: Type[] | undefined;
11833
11828
let hasDisjointDomainType = false;
@@ -18357,13 +18352,14 @@ namespace ts {
18357
18352
structuredTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck) :
18358
18353
recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck, recursionFlags);
18359
18354
// The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
18360
- // (1) Source is an intersection of object types { a } & { b } and target is an object type { a, b }.
18361
- // (2) Source is an object type { a, b: boolean } and target is a union { a, b: true } | { a, b: false }.
18362
- // (3) Source is an intersection { a } & { b: boolean } and target is a union { a, b: true } | { a, b: false }.
18363
- // (4) Source is an instantiable type with a union or intersection constraint and target is a union or intersection.
18364
- if (!result && (source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Object ||
18365
- source.flags & (TypeFlags.Object | TypeFlags.Intersection) && isUnionContainingMultipleObjectLikeTypes(target) ||
18366
- source.flags & TypeFlags.Instantiable && target.flags & TypeFlags.UnionOrIntersection)) {
18355
+ // Source is instantiable (e.g. source has union or intersection constraint).
18356
+ // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
18357
+ // Source is an intersection, target is an object (e.g. { a } & { b } <=> { a, b }).
18358
+ // Source is an intersection, target is a union (e.g. { a } & { b: boolean } <=> { a, b: true } | { a, b: false }).
18359
+ // Source is an intersection, target instantiable (e.g. string & { tag } <=> T["a"] constrained to string & { tag }).
18360
+ if (!result && (source.flags & TypeFlags.Instantiable ||
18361
+ source.flags & TypeFlags.Object && target.flags & TypeFlags.Union ||
18362
+ source.flags & TypeFlags.Intersection && target.flags & (TypeFlags.Object | TypeFlags.Union | TypeFlags.Instantiable))) {
18367
18363
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
18368
18364
resetErrorInfo(saveErrorInfo);
18369
18365
}
0 commit comments