Why does Object.keys on a Record return string[]?

Intuitively, one may expect Object.keys on Record<K, T> to return K[], but it instead returns string[]. Why?

What is a record?

A record of type Keys to Type is an object whose property keys of type Keys are mapped to property values of type Type. For example, a Record<string, number> is an object where any string property will return a number value. For example, obj.someString may return the number 123, because we are accessing a string property of obj: someString.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Charles Stover

Charles Stover

Staff front end engineer | Tech lead | Architect | charlesstover.com