Created
January 11, 2024 14:39
-
-
Save wojtekKrol/6ecd128db239cf1972b9f49315d29b3d to your computer and use it in GitHub Desktop.
TypeScript utility for type-safe dynamic key lookup
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
export const myObject = { | |
a: 1, | |
b: 2, | |
c: 3, | |
}; | |
const ObjectKeys = <Obj extends Object>(obj: Obj): (keyof Obj)[] => { | |
return Object.keys(obj) as (keyof Obj)[]; | |
}; | |
ObjectKeys(myObject).map(key => { | |
return myObject[key] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment