@@ -18207,13 +18207,12 @@ namespace ts {
18207
18207
let result = Ternary.False;
18208
18208
const saveErrorInfo = captureErrorCalculationState();
18209
18209
18210
- // Note that these checks are specifically ordered to produce correct results. In particular,
18211
- // we need to deconstruct unions before intersections (because unions are always at the top),
18212
- // and we need to handle "each" relations before "some" relations for the same kind of type.
18213
- if (source.flags & TypeFlags.UnionOrIntersection || target.flags & TypeFlags.UnionOrIntersection) {
18214
- result = getConstituentCount(source) * getConstituentCount(target) >= 4 ?
18215
- recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck, recursionFlags) :
18216
- structuredTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck);
18210
+ if ((source.flags & TypeFlags.Union || target.flags & TypeFlags.Union) && getConstituentCount(source) * getConstituentCount(target) < 4) {
18211
+ // We skip caching when source or target is a union with no more than three constituents.
18212
+ result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck);
18213
+ }
18214
+ else if (source.flags & TypeFlags.UnionOrIntersection || target.flags & TypeFlags.UnionOrIntersection) {
18215
+ result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck, recursionFlags);
18217
18216
}
18218
18217
if (!result && !(source.flags & TypeFlags.Union) && (source.flags & (TypeFlags.StructuredOrInstantiable) || target.flags & TypeFlags.StructuredOrInstantiable)) {
18219
18218
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
@@ -18677,17 +18676,17 @@ namespace ts {
18677
18676
const maybeStart = maybeCount;
18678
18677
maybeKeys[maybeCount] = id;
18679
18678
maybeCount++;
18679
+ const saveExpandingFlags = expandingFlags;
18680
18680
if (recursionFlags & RecursionFlags.Source) {
18681
18681
sourceStack[sourceDepth] = source;
18682
18682
sourceDepth++;
18683
+ if (!(expandingFlags & ExpandingFlags.Source) && isDeeplyNestedType(source, sourceStack, sourceDepth)) expandingFlags |= ExpandingFlags.Source;
18683
18684
}
18684
18685
if (recursionFlags & RecursionFlags.Target) {
18685
18686
targetStack[targetDepth] = target;
18686
18687
targetDepth++;
18688
+ if (!(expandingFlags & ExpandingFlags.Target) && isDeeplyNestedType(target, targetStack, targetDepth)) expandingFlags |= ExpandingFlags.Target;
18687
18689
}
18688
- const saveExpandingFlags = expandingFlags;
18689
- if (!(expandingFlags & ExpandingFlags.Source) && isDeeplyNestedType(source, sourceStack, sourceDepth)) expandingFlags |= ExpandingFlags.Source;
18690
- if (!(expandingFlags & ExpandingFlags.Target) && isDeeplyNestedType(target, targetStack, targetDepth)) expandingFlags |= ExpandingFlags.Target;
18691
18690
let originalHandler: typeof outofbandVarianceMarkerHandler;
18692
18691
let propagatingVarianceFlags: RelationComparisonResult = 0;
18693
18692
if (outofbandVarianceMarkerHandler) {
@@ -18713,13 +18712,13 @@ namespace ts {
18713
18712
if (outofbandVarianceMarkerHandler) {
18714
18713
outofbandVarianceMarkerHandler = originalHandler;
18715
18714
}
18716
- expandingFlags = saveExpandingFlags;
18717
18715
if (recursionFlags & RecursionFlags.Source) {
18718
18716
sourceDepth--;
18719
18717
}
18720
18718
if (recursionFlags & RecursionFlags.Target) {
18721
18719
targetDepth--;
18722
18720
}
18721
+ expandingFlags = saveExpandingFlags;
18723
18722
if (result) {
18724
18723
if (result === Ternary.True || (sourceDepth === 0 && targetDepth === 0)) {
18725
18724
if (result === Ternary.True || result === Ternary.Maybe) {
@@ -23150,7 +23149,7 @@ namespace ts {
23150
23149
}
23151
23150
23152
23151
function getConstituentCount(type: Type) {
23153
- return type.flags & TypeFlags.UnionOrIntersection ? (type as UnionOrIntersectionType ).types.length : 1;
23152
+ return type.flags & TypeFlags.Union ? (type as UnionType ).types.length : 1;
23154
23153
}
23155
23154
23156
23155
function extractTypesOfKind(type: Type, kind: TypeFlags) {
0 commit comments