@@ -7236,7 +7236,7 @@ namespace ts {
7236
7236
// because of constraints on type parameters (e.g. 'keyof T' for a constrained T).
7237
7237
// The isIndexType flag indicates that the type is the index type of an indexed
7238
7238
// access that is the target of an assignment.
7239
- function getLowerBoundOfKeyType(type: Type, isIndexType: boolean ): Type {
7239
+ function getLowerBoundOfKeyType(type: Type): Type {
7240
7240
if (type.flags & (TypeFlags.Any | TypeFlags.Primitive)) {
7241
7241
return type;
7242
7242
}
@@ -7246,7 +7246,7 @@ namespace ts {
7246
7246
if (type.flags & TypeFlags.Conditional) {
7247
7247
if ((<ConditionalType>type).root.isDistributive) {
7248
7248
const checkType = (<ConditionalType>type).checkType;
7249
- const constraint = getLowerBoundOfKeyType(checkType, isIndexType );
7249
+ const constraint = getLowerBoundOfKeyType(checkType);
7250
7250
if (constraint !== checkType) {
7251
7251
const mapper = makeUnaryTypeMapper((<ConditionalType>type).root.checkType, constraint);
7252
7252
return getConditionalTypeInstantiation(<ConditionalType>type, combineTypeMappers(mapper, (<ConditionalType>type).mapper));
@@ -7255,13 +7255,10 @@ namespace ts {
7255
7255
return type;
7256
7256
}
7257
7257
if (type.flags & TypeFlags.Union) {
7258
- return getUnionType(sameMap((<UnionType>type).types, t => getLowerBoundOfKeyType(t, isIndexType) ));
7258
+ return getUnionType(sameMap((<UnionType>type).types, getLowerBoundOfKeyType));
7259
7259
}
7260
7260
if (type.flags & TypeFlags.Intersection) {
7261
- return getIntersectionType(sameMap((<UnionType>type).types, t => getLowerBoundOfKeyType(t, isIndexType)));
7262
- }
7263
- if (isIndexType && type.flags & TypeFlags.Instantiable) {
7264
- return getLowerBoundOfKeyType(getConstraintOfType(type) || neverType, isIndexType);
7261
+ return getIntersectionType(sameMap((<UnionType>type).types, getLowerBoundOfKeyType));
7265
7262
}
7266
7263
return neverType;
7267
7264
}
@@ -7294,7 +7291,7 @@ namespace ts {
7294
7291
}
7295
7292
}
7296
7293
else {
7297
- forEachType(getLowerBoundOfKeyType(constraintType, /*isIndexType*/ false ), addMemberForKeyType);
7294
+ forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
7298
7295
}
7299
7296
setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
7300
7297
@@ -12879,27 +12876,18 @@ namespace ts {
12879
12876
}
12880
12877
}
12881
12878
else if (target.flags & TypeFlags.IndexedAccess) {
12882
- // A type S is related to a type T[K], where T and K aren't both type variables, if S is related to C,
12883
- // where C is the base constraint of T[K]
12879
+ // A type S is related to a type T[K] if S is related to C, where C is the base
12880
+ // constraint of T[K] for writing.
12884
12881
if (relation !== identityRelation) {
12885
12882
const objectType = (<IndexedAccessType>target).objectType;
12886
12883
const indexType = (<IndexedAccessType>target).indexType;
12887
- if (indexType.flags & TypeFlags.StructuredOrInstantiable) {
12888
- const keyType = getLowerBoundOfKeyType(indexType, /*isIndexType*/ true);
12889
- if (keyType !== indexType && !(keyType.flags & TypeFlags.Never)) {
12890
- const targetType = getIndexedAccessTypeOrUndefined(objectType, keyType, /*accessNode*/ undefined, AccessFlags.Writing);
12891
- if (targetType && (result = isRelatedTo(source, targetType, reportErrors))) {
12892
- return result;
12893
- }
12894
- }
12895
- }
12896
- else {
12897
- const constraint = getConstraintOfType(objectType);
12898
- if (constraint) {
12899
- const targetType = getIndexedAccessTypeOrUndefined(constraint, indexType, /*accessNode*/ undefined, AccessFlags.Writing | AccessFlags.NoIndexSignatures);
12900
- if (targetType && (result = isRelatedTo(source, targetType, reportErrors))) {
12901
- return result;
12902
- }
12884
+ const baseObjectType = getBaseConstraintOfType(objectType) || objectType;
12885
+ const baseIndexType = getBaseConstraintOfType(indexType) || indexType;
12886
+ if (!isGenericObjectType(baseObjectType) && !isGenericIndexType(baseIndexType)) {
12887
+ const accessFlags = AccessFlags.Writing | (baseObjectType !== objectType ? AccessFlags.NoIndexSignatures : 0);
12888
+ const constraint = getIndexedAccessTypeOrUndefined(baseObjectType, baseIndexType, /*accessNode*/ undefined, accessFlags);
12889
+ if (constraint && (result = isRelatedTo(source, constraint, reportErrors))) {
12890
+ return result;
12903
12891
}
12904
12892
}
12905
12893
}
0 commit comments