Skip to content

Commit 8120094

Browse files
committed
Simplify index and object types when obtaining indexed access constraint
1 parent 3745694 commit 8120094

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7657,15 +7657,20 @@ namespace ts {
76577657
return hasNonCircularBaseConstraint(type) ? getConstraintFromIndexedAccess(type) : undefined;
76587658
}
76597659

7660+
function getSimplifiedTypeOrConstraint(type: Type) {
7661+
const simplified = getSimplifiedType(type, /*writing*/ false);
7662+
return simplified !== type ? simplified : getConstraintOfType(type);
7663+
}
7664+
76607665
function getConstraintFromIndexedAccess(type: IndexedAccessType) {
7661-
const indexConstraint = getConstraintOfType(type.indexType);
7666+
const indexConstraint = getSimplifiedTypeOrConstraint(type.indexType);
76627667
if (indexConstraint && indexConstraint !== type.indexType) {
76637668
const indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint);
76647669
if (indexedAccess) {
76657670
return indexedAccess;
76667671
}
76677672
}
7668-
const objectConstraint = getConstraintOfType(type.objectType);
7673+
const objectConstraint = getSimplifiedTypeOrConstraint(type.objectType);
76697674
if (objectConstraint && objectConstraint !== type.objectType) {
76707675
return getIndexedAccessTypeOrUndefined(objectConstraint, type.indexType);
76717676
}

0 commit comments

Comments
 (0)