@@ -6899,10 +6899,15 @@ namespace ts {
6899
6899
}
6900
6900
6901
6901
function getConstraintOfIndexedAccess(type: IndexedAccessType) {
6902
- const objectType = getBaseConstraintOfType(type.objectType) || type.objectType;
6903
- const indexType = getBaseConstraintOfType(type.indexType) || type.indexType;
6904
- const constraint = !isGenericObjectType(objectType) && !isGenericIndexType(indexType) ? getIndexedAccessType(objectType, indexType, /*accessNode*/ undefined, errorType) : undefined;
6905
- return constraint && constraint !== errorType ? constraint : undefined;
6902
+ const objectType = getConstraintOfType(type.objectType) || type.objectType;
6903
+ if (objectType !== type.objectType) {
6904
+ const constraint = getIndexedAccessType(objectType, type.indexType, /*accessNode*/ undefined, errorType);
6905
+ if (constraint && constraint !== errorType) {
6906
+ return constraint;
6907
+ }
6908
+ }
6909
+ const baseConstraint = getBaseConstraintOfType(type);
6910
+ return baseConstraint && baseConstraint !== type ? baseConstraint : undefined;
6906
6911
}
6907
6912
6908
6913
function getDefaultConstraintOfConditionalType(type: ConditionalType) {
@@ -7074,9 +7079,6 @@ namespace ts {
7074
7079
if (t.flags & TypeFlags.Substitution) {
7075
7080
return getBaseConstraint((<SubstitutionType>t).substitute);
7076
7081
}
7077
- if (isGenericMappedType(t)) {
7078
- return emptyObjectType;
7079
- }
7080
7082
return t;
7081
7083
}
7082
7084
}
@@ -11642,12 +11644,13 @@ namespace ts {
11642
11644
}
11643
11645
}
11644
11646
else if (target.flags & TypeFlags.IndexedAccess) {
11645
- // A type S is related to a type T[K] if S is related to C, where C is the
11646
- // constraint of T[K]
11647
- const constraint = getConstraintForRelation(target);
11648
- if (constraint) {
11649
- if (result = isRelatedTo(source, constraint, reportErrors)) {
11650
- return result;
11647
+ // A type S is related to a type T[K] if S is related to C, where C is the base constraint of T[K]
11648
+ if (relation !== identityRelation) {
11649
+ const constraint = getBaseConstraintOfType(target);
11650
+ if (constraint && constraint !== target) {
11651
+ if (result = isRelatedTo(source, constraint, reportErrors)) {
11652
+ return result;
11653
+ }
11651
11654
}
11652
11655
}
11653
11656
}
0 commit comments