Last active
July 26, 2023 08:37
-
-
Save mayognaise/32b945b91442b0cc5bea721195aaa12a to your computer and use it in GitHub Desktop.
Create union type from object array
This file contains 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
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