Skip to content

Commit 3d3ed04

Browse files
committed
Perform indexed access type transformations consistently
1 parent 616bb5f commit 3d3ed04

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5906,6 +5906,10 @@ namespace ts {
59065906
}
59075907

59085908
function getConstraintOfIndexedAccess(type: IndexedAccessType) {
5909+
const transformed = getTransformedIndexedAccessType(type);
5910+
if (transformed) {
5911+
return transformed;
5912+
}
59095913
const baseObjectType = getBaseConstraintOfType(type.objectType);
59105914
const baseIndexType = getBaseConstraintOfType(type.indexType);
59115915
return baseObjectType || baseIndexType ? getIndexedAccessType(baseObjectType || type.objectType, baseIndexType || type.indexType) : undefined;
@@ -7617,8 +7621,8 @@ namespace ts {
76177621
return false;
76187622
}
76197623

7620-
// Transform an indexed access occurring in a read position to a simpler form. Return the simpler form,
7621-
// or undefined if no transformation is possible.
7624+
// Transform an indexed access to a simpler form, if possible. Return the simpler form, or return
7625+
// undefined if no transformation is possible.
76227626
function getTransformedIndexedAccessType(type: IndexedAccessType): Type {
76237627
const objectType = type.objectType;
76247628
// Given an indexed access type T[K], if T is an intersection containing one or more generic types and one or
@@ -9279,7 +9283,7 @@ namespace ts {
92799283
else if (target.flags & TypeFlags.IndexedAccess) {
92809284
// A type S is related to a type T[K] if S is related to A[K], where K is string-like and
92819285
// A is the apparent type of S.
9282-
const constraint = getConstraintOfType(<IndexedAccessType>target);
9286+
const constraint = getConstraintOfIndexedAccess(<IndexedAccessType>target);
92839287
if (constraint) {
92849288
if (result = isRelatedTo(source, constraint, reportErrors)) {
92859289
errorInfo = saveErrorInfo;
@@ -9319,7 +9323,7 @@ namespace ts {
93199323
else if (source.flags & TypeFlags.IndexedAccess) {
93209324
// A type S[K] is related to a type T if A[K] is related to T, where K is string-like and
93219325
// A is the apparent type of S.
9322-
const constraint = getTransformedIndexedAccessType(<IndexedAccessType>source) || getConstraintOfIndexedAccess(<IndexedAccessType>source);
9326+
const constraint = getConstraintOfIndexedAccess(<IndexedAccessType>source);
93239327
if (constraint) {
93249328
if (result = isRelatedTo(constraint, target, reportErrors)) {
93259329
errorInfo = saveErrorInfo;

0 commit comments

Comments
 (0)