Skip to content

Commit

Permalink
Less aggressive reduction in second pass union/intersection checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Feb 4, 2022
1 parent a65794c commit f269f42
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11823,11 +11823,6 @@ namespace ts {
return hasNonCircularBaseConstraint(type) ? getConstraintFromConditionalType(type) : undefined;
}

function hasStructuredOrInstantiableConstraint(type: Type) {
const constraint = type.flags & TypeFlags.Instantiable ? getConstraintOfType(type) : undefined;
return constraint && !!(constraint.flags & TypeFlags.StructuredOrInstantiable);
}

function isUnionContainingMultipleObjectLikeTypes(type: Type) {
return !!(type.flags & TypeFlags.Union) &&
countWhere((type as UnionType).types, t => !!(t.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags.Substitution))) >= 2;
Expand Down Expand Up @@ -18365,10 +18360,10 @@ namespace ts {
// (1) Source is an intersection of object types { a } & { b } and target is an object type { a, b }.
// (2) Source is an object type { a, b: boolean } and target is a union { a, b: true } | { a, b: false }.
// (3) Source is an intersection { a } & { b: boolean } and target is a union { a, b: true } | { a, b: false }.
// (4) Source is an instantiable type with a union constraint and target is a union.
// (4) Source is an instantiable type with a union or intersection constraint and target is a union or intersection.
if (!result && (source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Object ||
(source.flags & (TypeFlags.Object | TypeFlags.Intersection) && isUnionContainingMultipleObjectLikeTypes(target)) ||
(target.flags & TypeFlags.Union && hasStructuredOrInstantiableConstraint(source)))) {
source.flags & (TypeFlags.Object | TypeFlags.Intersection) && isUnionContainingMultipleObjectLikeTypes(target) ||
source.flags & TypeFlags.Instantiable && target.flags & TypeFlags.UnionOrIntersection)) {
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
resetErrorInfo(saveErrorInfo);
}
Expand Down

0 comments on commit f269f42

Please sign in to comment.