Skip to content

Instantly share code, notes, and snippets.

@mayognaise
Last active July 26, 2023 08:37
Show Gist options
  • Save mayognaise/32b945b91442b0cc5bea721195aaa12a to your computer and use it in GitHub Desktop.
Save mayognaise/32b945b91442b0cc5bea721195aaa12a to your computer and use it in GitHub Desktop.
Create union type from object array
const sizes = [
{ variant: 'sm', value: 8 },
{ variant: 'md', value: 16 },
{ variant: 'lg', value: 24 },
] as const
type SizeKey = keyof typeof sizes[number] // "variant" | "value"
type SizeVariant = typeof sizes[number]['variant'] // "sm" | "md" | "lg"
type SizeValue = typeof sizes[number]['value'] // 8 | 16 | 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment