{ [P in K]: T } is related to { [x: string]: U } if T is related to U

This commit is contained in:
Anders Hejlsberg
2017-08-05 10:09:44 -07:00
parent 86d0fa27a2
commit 44a6c6cc6f

View File

@@ -9614,6 +9614,11 @@ namespace ts {
if (sourceInfo) {
return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors);
}
if (isGenericMappedType(source)) {
// A generic mapped type { [P in K]: T } is related to an index signature { [x: string]: U }
// if T is related to U.
return kind === IndexKind.String && isRelatedTo(getTemplateTypeFromMappedType(<MappedType>source), targetInfo.type, reportErrors);
}
if (isObjectLiteralType(source)) {
let related = Ternary.True;
if (kind === IndexKind.String) {