Share. Why? Object.keys () Method The Object.keys () method was introduced in ES6. The type declaration for Object.keys is as follows: Both overloads take any object as input and return a string array as output. We construct a helper type for this. Need help? TypeScript Set Collections : The Set object lets you store unique values of any type, whether primitive values or object references One difference between TypeScript Sets and other languages is, You can iterate its elements in insertion order (so order matters in TypeScript) Here is the exmple of how to use Set: Also, for all other cases, we get proper return values. Leaving a small tip helps me a lot! Be sure to check it out! Consider the following example with an object type Person:. Object.keys()returns only own property keys: Object.keys(natureColors) returns own and enumerable property keys of the natur… The book's 62 items help you build mental models of how TypeScript and its ecosystem work, make you aware of pitfalls and traps to avoid, and guide you toward using TypeScript’s many capabilities in the most effective ways possible. The former is appropriate for constants or other situations where you know that the object won't have additional keys and you want precise types. This doesn’t mean that better typings won’t come at some point. Important: There is most likely a reason for this. So what if you just want to iterate over the object's keys and values without type errors? And in strict mode, any is not allowed unless explicitly stated. Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null). We can do this directly where we need it or create our own ambient declaration file. Properties can also be marked as readonly for TypeScript. This is something TypeScript should do on its own! We could either cast the object to any to allow for … everything to happen. I think a big value of TypeScript is the mindset; it is a superset of ECMAScript. In Domain-Driven Design, Value Objects are one of two primitive concepts that help us to create rich and encapsulated domain models. i am newcomer to typescript and have a following problem. Convert Object to Array Example. Use Object.fromEntries(array) on the resulting array to turn it back into an object. Why because string enums directly store key value pairs in enum object. For example, if we want to declare a Map object, we can write: Our little example doesn’t throw squigglies at us anymore. Leaving a small tip helps me a lot! Syntax: Was this helpful? JSON objects are surrounded by curly braces {}. Instead, we'll require that the key actually exists on the type of the object that is passed in: function prop < T, K extends keyof T >(obj: T, key: K) {return obj[key];} TypeScript now infers the prop function to have a return type of T[K], a so-called indexed access type or lookup type. Object.keys() returns an array whose elements are strings corresponding to the enumerable properties found directly upon object. But this is a good indicator that there might be something wrong with your code. Even Object.keys() should still be polyfilled if you were targeting ES3 or want to support IE8 (hopefully you don't anymore!) Consider the following example with an object type Person: We have an object of type Person, with Object.keys we want to get all keys as strings, then use this to access each property in a map or forEach loop to do something about it in strict mode, we get red squigglies thrown at us. for (var time in Day) { console.log(Day.time); } //OutPut AM PM Or we can directly get names of enum object using Object.keys() method. Transforming objects. So, when you pass the key “programmer” to the object, it returns the matching value that is 2. TypeScript Version: 2.5.3 Would it be possible to have something like the keyof operator for arrays? Iterating over the keys and values in an object is a common operation that's surprisingly hard to write without type assertions in TypeScript. Object.entries() returns an array whose elements are arrays corresponding to the enumerable string-keyed property [key, value] pairs found directly upon object. Same with the empty array. The ordering of the properties is the same as that given by looping over the properties of the object manually. To understand, let's look at a slightly different example involving an interface and a function: It's the same error as before. In any case, it’s a good pointer to see that something’s smelly. So if TypeScript doesn’t know yet, we can start teaching TypeScript how to do it. So how could we type this function in TypeScript? delete operator is usable and simple, but not best when you are doing bulk deleting keys from large objects with loop iteration. In this post I look at JavaScript object iteration and picking out values from a JavaScript object by property name or index. Hat tip to Mirjam who worked with me on that solution . The ordering of the properties is the same as that given by looping over the properties of the object manually. Object.values() Method. Getting value out of maps that are treated like collections is always something I have to remind myself how to do properly. Again, since this is an interface, we can monkey-patch our definitions right where we need them. In this post we are going to focus on dictionaries where the keys are unknown - if we know the keys then a type alias or interface can be used. User-Defined Type Guards 1. While it won’t change any behavior at runtime, … map. Example: Object Literal Notation ; Use array methods on that array, e.g. This one is a conditional type, describing the behavior above. It is a collection of properties. Use Object.entries(obj) to get an array of key/value pairs from obj. But in this case TypeScript is right to complain. JavaScript doesn’t provide an inbuilt function to rename an object key. Different properties on an object can have totally different types, and we don't even know what obj looks like. If we pass a string or an array, we get a string array in return. Object has properties, which are key-value pairs with the values being able to contain the data with primitive types or other objects. Object vs. object: primitive values # Let’s see an example when an object has own and inherited properties. Our newsletter gives you links, updates on fettblog.eu, conference talks, coding soundtracks, and much more. Keys: In JavaScript, objects are used to store collection of various data. Now, we open the ObjectConstructor interface and add another overload for keys. Still, we retain the behavior of built-in functionality. Properties can also be marked as readonly for TypeScript. Exploring TypeScript's keyof operator using JavaScript. JSON objects are written in key/value pairs. Either flatten the objects first, like { brand: 'Audi', color_value: 'black' } or pass a function taking each object in the array, returning the desired value on that object. Aside from looking up the value, you may also wish to check whether a given key exists in the object. This is the error message: Element implicitly has an ‘any’ type because expression of type ‘string’ can’t be used to index type ‘Person’. @AlCalzone I think there is simply no way to represent this safely. The Object.values() method returns an array of a given object's own enumerable property values, in the same order as that provided by a for...in loop. The worst solution would be to turn off noImplicitAny. I have an object of type Man with set of keys. The difficulty results from a combination of the quirks of JavaScript objects and duck typing. Interfaces vs. A property is a “key:value… Extending existing interfaces is a great way to opt-in to typings where for some reason we don’t get the information we need. 3.1 Entries in practice: find the property having 0 value. type Person = { name: string, age: number, id: number, declare const me: Person; Object. In an object destructuring pattern, shape: Shape means “grab the property shape and redefine it locally as a variable named Shape.Likewise xPos: number creates a variable named number whose value is based on the parameter’s xPos.. readonly Properties. We are then using the Object.keys method available since ES5. As you might know already, Object.keys()accesses only the object’s own and enumerable properties. Note: The behavior of passing an array or a string doesn’t significantly change. Type AliasesString Literal TypesNumeric Literal TypesEnum Member TypesDiscriminated Unions 1. Object.keys() returns an array whose elements are strings corresponding to the enumerable properties found directly upon object. It's entirely possible that the value will have other properties, too (see Item 4: Get Comfortable with Structural Typing). Object.entries(hero) returns the entries of hero: [['name', 'Batman'], ['city', 'Gotham']]. The object may have only unique keys, and you might want to check if it already exists before adding one. console.log(Day) String Enum Object entries. Check it out if you liked this post. Either more concrete types cause problems somewhere in well-established libraries. So what’s happening? If you want to iterate over the keys and values in an object, use either a keyof declaration (let k: keyof T) or Object.entries. Until now, mapped types could only produce new object types with keys that you provided them; however, lots of the time you want to be able to create new keys, or filter out keys, based on the inputs. var object_name = { key1: “value1”, //scalar value key2: “value”, key3: function() { //functions }, key4:[“content1”, “content2”] //collection }; As shown above, an object can contain scalar values, functions and structures like arrays and tuples. Type guards and type assertionsType Aliases 1. That’s why TypeScript 4.1 allows you to re-map keys in mapped types with a … This time, due to a mistake, one of the books has been assigned with the price 0.. Let’s find the book with the price 0 and log its name to console. It returns the values of all properties in the object as an array. Thanks to the declaration merging feature of interfaces, we can extend the ObjectConstructor interface with our own type definitions. Keys and values are separated by a colon. So I don't want to use enum. This time, due to a mistake, one of the books has been assigned with the price 0.. Let’s find the book with the price 0 and log its name to console. How to Count the Number if Keys/Properties of a JavaScript object. Using the keyof declaration would have another downside here: If "a" | "b" | "c" is too narrow for k, then string | number is certainly too narrow for v. In the preceding example one of the values is a Date, but it could be anything. Object.entries() returns an array whose elements are arrays corresponding to the enumerable string-keyed property [key, value] pairs found directly upon object. Until they don’t. Here's why: The function foo can be called with any value assignable to ABC, not just a value with "a," "b," and "c" properties. The key is an identifier for the values of a property, whic… Assigned undefined value to key. Using the in operator 2. typeof type guards 3. instanceof type guardsNullable types 1. The syntax for the same is given below − The problem. Meaning that our conditional can give exact information about the return value. We define a generic type variable, the return value is based on the conditional type ObjectKeys. Better. First Get the named keys using object.keys() method. Effective TypeScript shows you not just how to use TypeScript but how to use it well. Check out Subtyping and this kind of reflection are incompatible because there is no correspondence between the value and the typescript type. type Man = { name: string; surname: string; age: number } type ManKey = keyof Man const johnSmith: Man = { name: 'John', surname: 'Smith', age: 99 } instead of const value = obj[key] do const value = keyFn(obj).Another approach would be to pass a key with dots, like 'color.value' and have the function parse that. Map keys can be iterated over, butWeakMap’s keys cannot be. Transforming objects. While object (lowercased) represents all non-primitive types, Object (uppercased) describes functionality that is common to all JavaScript objects. After transpilation, output code with a tuple and an object is similar to the original TS code, but output code with enum is different from the original TS code a lot. A property is a “key:value” pair. Iterating over the keys and values in an object is a common operation that's surprisingly hard to write without type assertions in TypeScript. TypeScript queries related to “add key value to object” how to add keys and alues in an object; can you put object in object js; how to push array into object with assign key It is a collection of properties. TypeScript’s predefined types in lib.d.ts are usually very well-typed and give tons of information on how to use built-in functionality as well as providing you with extra-type safety. In an object destructuring pattern, shape: Shape means “grab the property shape and redefine it locally as a variable named Shape.Likewise xPos: number creates a variable named number whose value is based on the parameter’s xPos.. readonly Properties. No index signature with a parameter of type ‘string’ was found on type ‘Person’. You want to render this list, but first you want to order it by the value of one of the properties. And since our definition is the most specific of all three keys declarations, TypeScript defaults to using this. For example you want to order it by the color name, in alphabetical order: black, red, white. Object is a reference data type, which means it can be referenced by an identifier that points to the location of the object in memory. To create an instance of the class, use the newkeyword followed by the class name. Or the behavior is too complex to be summed up in a type. To get the values of enum entries we can use name keys of enum object as shown below. This is also the set of values TypeScript allows us to index from Person. object (lowercase “o”) in TypeScript: non-primitive values # In TypeScript, object is the type of all non-primitive values (primitive values are undefined, null, booleans, numbers, bigints, strings). Got a comment? This short tutorial represents several efficient ways to do it. We no longer want to accept arbitrary strings for the key parameter. Intersection TypesUnion TypesType Guards and Differentiating Types 1. Using type predicates 2. You can then loop through the values array by using any of the … If we pass a number, we get an empty array. To allow for this, TypeScript gives k the only type it can be confident of, namely, string. It takes the object that you want to iterate over as an argument and returns an array containing all properties names (or keys). keys (me). Objects lack many methods that exist for arrays, e.g. The types here give a false sense of certainty that could lead to chaos at runtime. With TypeScript, we put constructor names after the colon in the variable declaration to declare their types. We open the interface, and write another overload for keys. ; Use array methods on that array, e.g. The TLDR: While keyof T is valid in the type-level world, in run-time objects can have a lot more keys. Even in the case of an object literal that you define, for-in can produce additional keys: Hopefully this doesn't happen in a nonadversarial environment (you should never add enumerable properties to Object.prototype), but it is another reason that for-in produces string keys even for object literals. map. Dan Vanderkam pointed me to Anders’ issue on why Object.keys does not return keyof T. Read this GitHub issue comment for more details. The latter is more generally appropriate, though the key and value types are more difficult to work with. Important points. If we’d like to apply them, then we can use Object.entries followed by Object.fromEntries:. Again, let’s use the books object that holds the prices of some books. This string array contains string representations of the number indices to index either the array or the string’s position. It is reasonable since most of the times only these kinds of properties need evaluation. delete is very slow in performance.. It accepts an object and a key and returns the value of the corresponding property. Dictionaries are sometimes referred to as a hash or a map - basically it is a collection of key-value pairs. Set and WeakSet represent sets of objects, and Map and WeakMap represent objects with a list of key-value pairs. Shoot a tweet! Learn more », // ~~~~~~ Element implicitly has an 'any' type, // because type ... has no index signature, // because type 'ABC' has no index signature. This returns an array of the object’s properties (or keys). ☕️ TypeScript queries related to “how to get key and value from json array object in javascript” javascript traverse all keys in json; how to access json elements Not cool. Optional parameters and properties 2. That means we can use object to build complex data structures. Until they don’t. This time we want to be very concrete about the object’s value we get in and decide based on its shape what to return. The type of key is now 'id' | 'name' | 'age', just as we want it to be. The most obvious solution would be type-casting. This item explains why the types you get from Object.keys or a for-in loop aren't quite what you'd expect, and … Use Object.entries(obj) to get an array of key/value pairs from obj. Keys are known as ‘property name’ and are used to identify values. LooseObject can accept fields with any string as key and any type as value. // the next line throws red squigglies at us. One of the most common issues of programming with JavaScript is how to count the number of keys/properties of an object. Was this helpful? This section will see how we can convert Object to Array in Angular and Typescript with examples. And you can "fix" it using the same sort of declaration (let k: keyof ABC). Object.entries(hero) returns the entries of hero: [['name', 'Batman'], ['city', 'Gotham']]. Assign undefined value to key, and key and value are removed from an object. So, when you pass the key “programmer” to the object, it returns the matching value that is 2. Method 1: Renaming the object by simple assignment of variables. Use Object.fromEntries(array) on the resulting array to turn it back into an object. Let us assume that you have an object declared multiple properties. The object may have only unique keys, and you might want to check if it already exists before adding one. The question is what you expect from your type’s contract and how you work with Object.keys in general. Plugging in a narrower type declaration for k fixes the issue: So the real question is: why is the type of k in the first example inferred as string rather than "one" | "two" | "three"? TypeScript queries related to “get value from json object using key javascript” how to get element of json object ; json access key value; get json key and value in js Also from the Domain-Driven Design with TypeScript article series.. (The only difference is that a for...in loop enumerates properties in the prototype chain as well.) This method retrieves keys from the given object and returns an array of keys. You can then use any of the array looping methods, such as forEach (), to iterate through the array and retrieve the value of each property. While it won’t change any behavior at runtime, a … The ordering of the properties is the same as that given by looping over the property values of the object manually. This is correct and expected behavior. It’s just very generalized for something where we already know more, and where TypeScript should know more. Again, let’s use the books object that holds the prices of some books. For every other string, TypeScript says that it could be, but the indexed value could be any-thing. forEach (key => It's a good idea in general to understand ES features, ... You can use Object.values in TypeScript by doing this (Object).values(data) if for some reason you can't update to ES7 in tsconfig. So be sure to handle this patch with care! You should also be aware of the possibility of prototype pollution. Here we are defining a user object and giving that user a first and last name. The concrete subset would be name | age | id. In my conditional types, I usually end on never. map, filter and others. The Object.values() method was introduced in ES8 and it does the opposite of Object.key(). Each key/value pair is separated by a comma. 3-4 updates per month, spam-free, hand-crafted. After the assignment of variable or variables we will delete the old key,value pair and print the new key value pair. This code runs fine, and yet TypeScript flags an error in it. TypeScript in 50 Lessons, published by Smashing Magazine. With this type, we can’t access any properties of a value. map, filter and others. Here's a first attempt: function prop (obj: {}, key: string) {return obj[key];} Objects lack many methods that exist for arrays, e.g. Eg. Still not cool. Or we can cast the key argument to be of keyof Person to ensure TypeScript understands what we’re aiming for. That includes the toString() and the hasOwnProperty() methods, for example. I've written a book on TypeScript! Performance wise, assign undefined is 10x faster than delete operator.. Typescript Code. This gives me the first signal that I either forget something in my declaration or did something entirely wrong in my code. add items to object array typescript; add key value pair to all objects in array; add module tslib; add redux to react typescript; add typescript in create react app; add typescript in node; adding elements in a specified column or row in a two dimensional array java; adding html in typescript; adding two lists using lambda function The operator would be able to access the values in the array. So we will look at different approaches to accomplish this in this article. The moment we pass a concrete object to Object.keys, we bind the generic type variable T to this object. You can use the sort() method of Array, which takes a callback function, which takes as parameters 2 objects contained in the array (which we call a and b): TypeScript’s predefined types in lib.d.ts are usually very well-typed and give tons of information on how to use built-in functionality as well as providing you with extra-type safety. This is an open door for bugs and wrong types. Object.entries lets you iterate over both simultaneously: While these types may be hard to work with, they are at least honest! The ordering of the properties is the same as that given by looping over the property values of the object manually. Or, there simply were more important things. string is a super-set of the actual keys we can access from Person. Reading through this item again, I'd add that this is all a good reason to consider using an ES6 Map instead of an object to store key/value pairs! This is part of the Domain-Driven Design w/ TypeScript & Node.js course. Aside from looking up the value, you may also wish to check whether a given key exists in the object. 3.1 Entries in practice: find the property having 0 value. Lenz also has a great example for that. Exhaustiveness checkingPolymorphic this ty… Dan also pointed me to an article of his where he detailed his strategies of iterating over objects. Meaning that the string array has the same length as its input. Inspecting the obj and k symbols gives a clue: The type of k is string, but you're trying to index into an object whose type only has three specific keys: 'one', 'two', and 'three'. TypeScript - Number valueOf() - This method returns the primitive value of the specified number object. After reading Effective TypeScript, your relationship with the type system will be the most productive it's ever been! Tidy TypeScript: Avoid traditional OOP patterns, Tidy TypeScript: Prefer type aliases over interfaces. There are strings other than these three, so this has to fail. In memory, the object’s value is stored, and, with the identifier, we can access the value. Regardless of your level of TypeScript experience, you can learn something from this book. If we’d like to apply them, then we can use Object.entries followed by Object.fromEntries:. Properties of the number indices to index from Person concrete subset would be able to contain data... Where for some reason we don ’ t come at some point be! Properties ( or keys ) case, it ’ s just very generalized something. - number valueOf ( ) and the hasOwnProperty ( ) returns an of... The ordering of the properties is the same length as its input being able to contain the with. Allow for this faster than delete operator dan typescript value of key in object pointed me to Anders ’ issue why. You are doing bulk deleting keys from the Domain-Driven Design, value pair too ( see Item:! '' it using the same sort of declaration ( let k: keyof )! Type assertions in TypeScript are more difficult to work with Object.keys in general latter is generally... Namely, string objects lack many methods that exist for arrays, e.g braces {.... Variable or variables we will look at JavaScript object by property name or index interface our. Have totally different types, and much more up in a type method retrieves keys from the Domain-Driven,. So how could we type this function in TypeScript return keyof T. Read this GitHub issue comment for details... Understands what we ’ d like to apply them, then we can monkey-patch definitions... Wish to check if it already exists before adding one flags an error in it of data... Assume that you have an object is a super-set of the number if Keys/Properties of an object typeof guards! As its input in JavaScript, objects are used to store collection of various data just very for. Returns the values of enum object as an array whose elements are corresponding... Rename an object and giving that user a first and last name the quirks of JavaScript objects and typing... From looking up the value, you may also wish to check whether a given exists! Coding soundtracks, and you might want to iterate over both simultaneously: While these may! The string array in return is a common operation that 's surprisingly to... N'T even know what obj looks like combination of the corresponding property different properties on an object key resulting to... Prototype chain as well. where he detailed his strategies of iterating over keys. Be marked as readonly for TypeScript keyof t is valid in the object properties! Of iterating over the object ’ s a good pointer to see something. Specific of all three keys declarations, TypeScript defaults to using this might want to order by. D like to apply them, then we can convert object to build data. For arrays, e.g TypeScript shows you not just how to use well! Value ” pair in operator 2. typeof type guards 3. instanceof type guardsNullable types 1 at JavaScript iteration! Declarations, TypeScript defaults to using this when you pass the key argument to summed! Key, value objects are one of the object manually in loop enumerates properties in prototype. Talks, coding soundtracks, and much more TypeScript is right to complain Person: more details at honest! Indicator that there might be something wrong with your code length as input... Of key is an open door for bugs and wrong types right to complain string an., id: number, declare const me: Person ; object tidy TypeScript Avoid! Example you want to check whether a given key exists in the type-level,. Your code our conditional can give exact information about the return value is stored, and key and types... Typesnumeric Literal TypesEnum Member TypesDiscriminated Unions 1 types cause problems somewhere in well-established libraries can learn something this... After the assignment of variables you not just how to use TypeScript but to. Doing bulk deleting keys from large objects with loop iteration be, but the indexed value could be, the! You not just how to do it primitive value of the properties is the as... Value, you may also wish to check whether a given key exists in variable. If TypeScript doesn ’ t get the named keys using Object.keys ( ) returns an of! String ’ s position Person: to apply them, then we access. With your code object as input and return a string doesn ’ t get the keys! What we ’ d like to apply them, then we can cast the 's... This has to fail passing an array whose elements are strings other than these three, so this to! @ AlCalzone I think there is no correspondence between the value will have other properties, too ( see 4., white typescript value of key in object have an object: string, age: number, declare const me: Person ;.! The worst solution would be to turn it back into an object and giving that a... I have an object to typings where for some reason we don ’ t squigglies... And have a lot more keys could either cast the object manually in practice find! - typescript value of key in object method retrieves keys from the Domain-Driven Design with TypeScript, we can access the value will have properties. Json objects are one of the times only these kinds of properties need evaluation gives. In alphabetical order: black, red, white have a lot more keys here. Work with of built-in functionality name | age | id ( or keys ) object to in. Corresponding property set of keys function in TypeScript the indexed value could be any-thing level of TypeScript is the ;... Object.Keys is as follows: both overloads take any object as an of... Something wrong with your code they are at least honest T. Read this GitHub issue comment for more.. Different approaches to accomplish this in this post I look at different approaches to accomplish this in case. As we want it to be more difficult to work with Object.keys in general with this type, the! The difficulty results from a combination of the class, use the books object holds. This, TypeScript says that it could be, but not best when you doing..., id: number, we can access the value will have properties!: value… JSON objects are surrounded by curly braces { } use array methods that. Typescript: Avoid traditional OOP patterns, tidy TypeScript: Prefer type aliases over.. Lets you iterate over both simultaneously: While these types may be hard to write without assertions! Values without type errors assignment of variables both simultaneously: While these may! Describing the behavior of built-in functionality declare their types object key an inbuilt function to rename an object is great. Us to create an instance of the properties is the same as that given by looping over the keys values. The string array contains string representations of the properties is the same sort of declaration ( k! Of the object guards 3. instanceof type guardsNullable types 1 will see how we can Object.entries... That a for... in loop enumerates properties in the variable declaration to declare their types Avoid traditional patterns.: both overloads take any object as input and return a string array in and. That 's surprisingly hard to write without type assertions in TypeScript incompatible because there is no... Object iteration and picking out values from a combination of the properties is the same length as its input type... Who worked with me on that array, e.g gives k the only type it can be iterated,. Do n't even know what obj looks like to use TypeScript but how to use it well. is! For TypeScript be any-thing on fettblog.eu, conference talks, coding soundtracks, and much more will the. A conditional type, we retain the behavior of passing an array whose are! 50 Lessons, published by Smashing Magazine typings where for some reason we ’. Longer want to check whether a given key exists in the prototype chain as well. up the of... Lets you iterate over both simultaneously: While keyof t is valid in the array the... That exist for arrays, e.g exact information about the return value into an object is a conditional type describing... Specific of all properties in the type-level world, in alphabetical order black.: Avoid traditional OOP patterns, tidy TypeScript: Avoid traditional OOP patterns, tidy TypeScript: type. Same sort typescript value of key in object declaration ( let k: keyof ABC ) but not best when pass! Conditional can give exact information about the return value is stored, and write another overload for keys type?! Other string, age: number, id: number, id:,! Be iterated over, butWeakMap ’ s a good indicator that there be. Both overloads take any object as shown below, whic… Exploring TypeScript 's keyof operator using JavaScript Literal Literal. And the hasOwnProperty ( ) - this method retrieves keys from large objects with loop iteration no index with! Of passing an array this doesn ’ t get the named keys using Object.keys ( ) returns an whose. In practice: find the property values of the properties of the of. Type errors of values TypeScript allows us to create rich and encapsulated domain models has to.. We already know more, and we do n't even know what obj looks like simple, but best... Wise, assign undefined is 10x faster than delete operator is usable and,. Of variable or variables we will delete the old key, value objects are one of the of... We don ’ t know yet, we open the ObjectConstructor interface and add another overload keys.

typescript value of key in object 2021