@@ -9454,32 +9454,30 @@ namespace ts {
9454
9454
}
9455
9455
}
9456
9456
}
9457
+ else if (isGenericMappedType(target) && !isGenericMappedType(source) && getConstraintTypeFromMappedType(<MappedType>target) === getIndexType(source)) {
9458
+ // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X.
9459
+ const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(<MappedType>target));
9460
+ const templateType = getTemplateTypeFromMappedType(<MappedType>target);
9461
+ if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {
9462
+ errorInfo = saveErrorInfo;
9463
+ return result;
9464
+ }
9465
+ }
9457
9466
9458
9467
if (source.flags & TypeFlags.TypeParameter) {
9459
- // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X.
9460
- if (getObjectFlags(target) & ObjectFlags.Mapped && getConstraintTypeFromMappedType(<MappedType>target) === getIndexType(source)) {
9461
- const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(<MappedType>target));
9462
- const templateType = getTemplateTypeFromMappedType(<MappedType>target);
9463
- if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {
9468
+ let constraint = getConstraintOfTypeParameter(<TypeParameter>source);
9469
+ // A type parameter with no constraint is not related to the non-primitive object type.
9470
+ if (constraint || !(target.flags & TypeFlags.NonPrimitive)) {
9471
+ if (!constraint || constraint.flags & TypeFlags.Any) {
9472
+ constraint = emptyObjectType;
9473
+ }
9474
+ // Report constraint errors only if the constraint is not the empty object type
9475
+ const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
9476
+ if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
9464
9477
errorInfo = saveErrorInfo;
9465
9478
return result;
9466
9479
}
9467
9480
}
9468
- else {
9469
- let constraint = getConstraintOfTypeParameter(<TypeParameter>source);
9470
- // A type parameter with no constraint is not related to the non-primitive object type.
9471
- if (constraint || !(target.flags & TypeFlags.NonPrimitive)) {
9472
- if (!constraint || constraint.flags & TypeFlags.Any) {
9473
- constraint = emptyObjectType;
9474
- }
9475
- // Report constraint errors only if the constraint is not the empty object type
9476
- const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
9477
- if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
9478
- errorInfo = saveErrorInfo;
9479
- return result;
9480
- }
9481
- }
9482
- }
9483
9481
}
9484
9482
else if (source.flags & TypeFlags.IndexedAccess) {
9485
9483
// A type S[K] is related to a type T if A[K] is related to T, where K is string-like and
0 commit comments