Allow intersections of readonlys to be assignable to a readonly intersection (#28218)

* Allow intersections of readonlys to be assignable to a readonly intersection

* Add real motivating react example to test suite
This commit is contained in:
Wesley Wigham
2018-10-31 14:09:12 -07:00
committed by GitHub
parent 0ef844ff2b
commit 3a2f7c0df1
9 changed files with 221 additions and 1 deletions

View File

@@ -12036,13 +12036,15 @@ namespace ts {
return Ternary.True;
}
// A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X.
if (!isGenericMappedType(source) && getConstraintTypeFromMappedType(target) === getIndexType(source)) {
if (!isGenericMappedType(source) && isRelatedTo(getConstraintTypeFromMappedType(target), getIndexType(source))) {
const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target));
const templateType = getTemplateTypeFromMappedType(target);
if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {
return result;
}
}
originalErrorInfo = errorInfo;
errorInfo = saveErrorInfo;
}
}