Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Created June 24, 2019 18:22
Show Gist options
  • Save Willmo36/842f76fbb0322455524b66b22e857580 to your computer and use it in GitHub Desktop.
Save Willmo36/842f76fbb0322455524b66b22e857580 to your computer and use it in GitHub Desktop.
Turn a record into a union of {key,value} objects
// 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