Skip to content

Commit c930975

Browse files
committed
Handle intersections in isDeeplyNestedType
1 parent 02269e4 commit c930975

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/compiler/checker.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -20946,8 +20946,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2094620946
// declare let wrong: { a: { y: string } };
2094720947
// let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
2094820948
//
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)) {
2095120951
result &= propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, /*optionalsOnly*/ false, IntersectionState.None);
2095220952
if (result && isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral) {
2095320953
result &= indexSignaturesRelatedTo(source, target, /*sourceIsPrimitive*/ false, reportErrors, IntersectionState.None);
@@ -20960,7 +20960,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2096020960
// x = y; // Mismatched property in source intersection
2096120961
// }
2096220962
//
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))) {
2096420966
result &= propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, /*optionalsOnly*/ true, intersectionState);
2096520967
}
2096620968
}
@@ -22596,12 +22598,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2259622598
// to terminate the expansion, and we do so here.
2259722599
function isDeeplyNestedType(type: Type, stack: Type[], depth: number, maxDepth = 3): boolean {
2259822600
if (depth >= maxDepth) {
22601+
if (type.flags & TypeFlags.Intersection) {
22602+
return some((type as IntersectionType).types, t => isDeeplyNestedType(t, stack, depth, maxDepth));
22603+
}
2259922604
const identity = getRecursionIdentity(type);
2260022605
let count = 0;
2260122606
let lastTypeId = 0;
2260222607
for (let i = 0; i < depth; i++) {
2260322608
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) {
2260522610
// We only count occurrences with a higher type id than the previous occurrence, since higher
2260622611
// type ids are an indicator of newer instantiations caused by recursion.
2260722612
if (t.id >= lastTypeId) {

0 commit comments

Comments
 (0)