Skip to content

Commit cca7ac2

Browse files
committed
Use immediate constraint, not base constraint, of indexed access
1 parent 9e8b3d9 commit cca7ac2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7942,16 +7942,9 @@ namespace ts {
79427942
}
79437943
}
79447944
else if (target.flags & TypeFlags.IndexedAccess) {
7945-
// if we have indexed access types with identical index types, see if relationship holds for
7946-
// the two object types.
7947-
if (source.flags & TypeFlags.IndexedAccess && (<IndexedAccessType>source).indexType === (<IndexedAccessType>target).indexType) {
7948-
if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType, reportErrors)) {
7949-
return result;
7950-
}
7951-
}
79527945
// A type S is related to a type T[K] if S is related to A[K], where K is string-like and
79537946
// A is the apparent type of S.
7954-
const constraint = getBaseConstraintOfType(target);
7947+
const constraint = getConstraintOfType(<IndexedAccessType>target);
79557948
if (constraint) {
79567949
if (result = isRelatedTo(source, constraint, reportErrors)) {
79577950
errorInfo = saveErrorInfo;
@@ -7998,6 +7991,13 @@ namespace ts {
79987991
return result;
79997992
}
80007993
}
7994+
else if (target.flags & TypeFlags.IndexedAccess && (<IndexedAccessType>source).indexType === (<IndexedAccessType>target).indexType) {
7995+
// if we have indexed access types with identical index types, see if relationship holds for
7996+
// the two object types.
7997+
if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType, reportErrors)) {
7998+
return result;
7999+
}
8000+
}
80018001
}
80028002
else {
80038003
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {

0 commit comments

Comments
 (0)