Created
February 6, 2024 14:05
-
-
Save ReVoid/29eae8b7b6a60fea93105de15caf198b to your computer and use it in GitHub Desktop.
Strongly typed Object.keys()
This file contains hidden or 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
type Key<T extends object> = keyof T; | |
type Keys<T extends object> = Array<Key<T>>; | |
function keysOf<T extends object>(value: T): Keys<T> { | |
const keys: string[] = Object.keys(value); | |
return keys as Keys<T>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment