Skip to content

Instantly share code, notes, and snippets.

@fend25
Created May 8, 2020 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fend25/6288aabd0065ac3b4d6492b34ef4949d to your computer and use it in GitHub Desktop.
Save fend25/6288aabd0065ac3b4d6492b34ef4949d to your computer and use it in GitHub Desktop.
Typescript. Typed versions of Object.keys, Object.values, Object.entries
export const getKeys = <T extends Object>(o: T) => Object.keys(o) as Array<keyof T>
export const getValues = <T extends Object>(o: T) => Object.values(o) as Array<T[keyof T]>
export const getEntries = <T extends Object>(o: T) => Object.entries(o) as Array<[keyof T, T[keyof T]]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment