Skip to content

Commit eeabd52

Browse files
committed
Examine all constraints of indexed access types in relations
1 parent b50c37d commit eeabd52

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6899,10 +6899,15 @@ namespace ts {
68996899
}
69006900

69016901
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;
69066911
}
69076912

69086913
function getDefaultConstraintOfConditionalType(type: ConditionalType) {
@@ -7074,9 +7079,6 @@ namespace ts {
70747079
if (t.flags & TypeFlags.Substitution) {
70757080
return getBaseConstraint((<SubstitutionType>t).substitute);
70767081
}
7077-
if (isGenericMappedType(t)) {
7078-
return emptyObjectType;
7079-
}
70807082
return t;
70817083
}
70827084
}
@@ -11642,12 +11644,13 @@ namespace ts {
1164211644
}
1164311645
}
1164411646
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+
}
1165111654
}
1165211655
}
1165311656
}

0 commit comments

Comments
 (0)