I would like to retrieve the values of the object in the array to declare a type in TypeScript, but it is not working as expected.
1.
const CuisineTypeOptions: { label: string; value: string }[] = [
{ label: 'Traditional', value: 'traditional' },
{ label: 'Typical', value: 'typical' },
] as const
type Type = (typeof CuisineTypeOptions)[number]['value'] // -> string
const CuisineTypeOptions = [
{ label: 'Traditional', value: 'traditional' },
{ label: 'Typical', value: 'typical' },
] as const
type Type = (typeof CuisineTypeOptions)[number]['value'] // -> 'traditional' | 'typical'
Could you please explain how to make the Type in code 1 work the same way as the Type in code 2?