Change 'keyof T' to always be string-like by ahejlsberg · Pull Request #12425 · microsoft/TypeScript (original) (raw)
This PR revises keyof T
to always be a subtype of string
vs. a subtype of string | number
. This more accurately reflects how properties work in JavaScript and allows us to use keyof T
as the inferred type of a for...in
variable when the object is of a type parameter type.
This change means that numeric index signatures are ignored by the keyof T
operator and that it is never possible to use numbers as values for a keyof T
.
Fixes #12314.