@@ -20946,8 +20946,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20946
20946
// declare let wrong: { a: { y: string } };
20947
20947
// let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
20948
20948
//
20949
- if (result && !(intersectionState & IntersectionState.Target) &&
20950
- target.flags & TypeFlags.Intersection && !isGenericObjectType(target) && source.flags & (TypeFlags.Object | TypeFlags.Intersection)) {
20949
+ if (result && !(intersectionState & IntersectionState.Target) && target.flags & TypeFlags.Intersection &&
20950
+ !isGenericObjectType(target) && source.flags & (TypeFlags.Object | TypeFlags.Intersection)) {
20951
20951
result &= propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, /*optionalsOnly*/ false, IntersectionState.None);
20952
20952
if (result && isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral) {
20953
20953
result &= indexSignaturesRelatedTo(source, target, /*sourceIsPrimitive*/ false, reportErrors, IntersectionState.None);
@@ -20960,7 +20960,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20960
20960
// x = y; // Mismatched property in source intersection
20961
20961
// }
20962
20962
//
20963
- else if (result && isNonGenericObjectType(target) && !isArrayOrTupleType(target) && source.flags & TypeFlags.Intersection && getApparentType(source).flags & TypeFlags.StructuredType && !some((source as IntersectionType).types, t => !!(getObjectFlags(t) & ObjectFlags.NonInferrableType))) {
20963
+ else if (result && isNonGenericObjectType(target) && !isArrayOrTupleType(target) &&
20964
+ source.flags & TypeFlags.Intersection && getApparentType(source).flags & TypeFlags.StructuredType &&
20965
+ !some((source as IntersectionType).types, t => !!(getObjectFlags(t) & ObjectFlags.NonInferrableType))) {
20964
20966
result &= propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, /*optionalsOnly*/ true, intersectionState);
20965
20967
}
20966
20968
}
@@ -22596,12 +22598,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
22596
22598
// to terminate the expansion, and we do so here.
22597
22599
function isDeeplyNestedType(type: Type, stack: Type[], depth: number, maxDepth = 3): boolean {
22598
22600
if (depth >= maxDepth) {
22601
+ if (type.flags & TypeFlags.Intersection) {
22602
+ return some((type as IntersectionType).types, t => isDeeplyNestedType(t, stack, depth, maxDepth));
22603
+ }
22599
22604
const identity = getRecursionIdentity(type);
22600
22605
let count = 0;
22601
22606
let lastTypeId = 0;
22602
22607
for (let i = 0; i < depth; i++) {
22603
22608
const t = stack[i];
22604
- if (getRecursionIdentity(t) === identity) {
22609
+ if (t.flags & TypeFlags.Intersection ? some((t as IntersectionType).types, u => getRecursionIdentity(u) === identity) : getRecursionIdentity(t) === identity) {
22605
22610
// We only count occurrences with a higher type id than the previous occurrence, since higher
22606
22611
// type ids are an indicator of newer instantiations caused by recursion.
22607
22612
if (t.id >= lastTypeId) {
0 commit comments