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.

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

MounteBank- Concept of Predicates

//platform.twitter.com/widgets.js from Twitter https://twitter.com/DaveBuysOrlando

WHAT IS ANGULAR CLI? HOW IS IT DIFFERENT FROM ANGULARJS?

Angular CLI vs. AngularJS

The Basics of Vue.js Components

What Is An Object in Object Oriented Programming?

Show Calendar — Part 2: Implementing Event Sourcing (for Dummies!)

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

More from Medium

An introduction to type programming in TypeScript — zhenghao

How to think about TypeScript

Coding Adventure: PositiveNumber in TypeScript

The unknown type in TypeScript

Photo by <a href=”https://unsplash.com/@frankiefoto?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">frank mckenna</a> on <a href=”https://unsplash.com/s/photos/ocean?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>