Created
June 24, 2019 18:22
-
-
Save Willmo36/842f76fbb0322455524b66b22e857580 to your computer and use it in GitHub Desktop.
Turn a record into a union of {key,value} objects
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
// Convert record to union of its members | |
// eg {foo: string, bar: number} -> {key: 'foo', value: string} | {key: 'bar' value: number}; | |
type RecordUnion<T extends Record<string, any>> = { | |
[K in keyof T]: { key: K, value: T[K] } | |
}[keyof T]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment