Created
April 9, 2024 11:33
-
-
Save roboli/d8fd5b5885a4708c0d1b5138da124b92 to your computer and use it in GitHub Desktop.
Using Object.keys(obj) in Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function objectKeys<T>(obj: T): (keyof T)[] { | |
return Object.keys(obj) as (keyof T)[]; | |
} | |
// ... | |
// Avoid the array of strings coming from Object.keys in TS source https://twitter.com/mattpocockuk/status/1502264005251018754?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed%7Ctwterm%5E1502264005251018754%7Ctwgr%5E1d1ec82885093024cd07b1d7a4a1d21f4e095a76%7Ctwcon%5Es1_c10&ref_url=https%3A%2F%2Fwww.mattstobbs.com%2Fobject-keys-typescript%2F | |
// objectKeys(myObj).find( ... ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment