Make keyof T assignable to and subtype of string | number

This commit is contained in:
Anders Hejlsberg 2016-11-08 10:14:44 -08:00
parent 7ca5923214
commit a562d6e63f

View File

@ -6917,6 +6917,13 @@ namespace ts {
if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
if (source.flags & TypeFlags.Index) {
// A keyof T is related to a union type containing both string and number
if (maybeTypeOfKind(target, TypeFlags.String) && maybeTypeOfKind(target, TypeFlags.Number)) {
return Ternary.True;
}
}
if (getObjectFlags(source) & ObjectFlags.ObjectLiteral && source.flags & TypeFlags.FreshLiteral) {
if (hasExcessProperties(<FreshObjectLiteralType>source, target, reportErrors)) {
if (reportErrors) {