Skip to content

Commit b82966f

Browse files
committed
Restructure and back off a little bit more
1 parent 1312e8a commit b82966f

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/compiler/checker.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -11823,11 +11823,6 @@ namespace ts {
1182311823
return hasNonCircularBaseConstraint(type) ? getConstraintFromConditionalType(type) : undefined;
1182411824
}
1182511825

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-
1183111826
function getEffectiveConstraintOfIntersection(types: readonly Type[], targetIsUnion: boolean) {
1183211827
let constraints: Type[] | undefined;
1183311828
let hasDisjointDomainType = false;
@@ -18357,13 +18352,14 @@ namespace ts {
1835718352
structuredTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck) :
1835818353
recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck, recursionFlags);
1835918354
// 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))) {
1836718363
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
1836818364
resetErrorInfo(saveErrorInfo);
1836918365
}

0 commit comments

Comments
 (0)