Is it possible to create a readonly item array
from a constant array?
const const basicValueTypes = [{
value: 'number',
label: 'Number'
},{
value: 'boolean',
label: 'Boolean'
}];
type ReadonlyItemArray = ???
type ReadOnlyBasicValueTypes = ReadonlyItemArray<typeof basicValueTyeps>;
/*
↓↓↓↓
ReadOnlyBasicValueTypes = (
{value: 'number', label: 'Number'}
| {value: 'boolean', label: 'Boolean'}
)
*/
Update:
I discovered that I can make each item as const
:
const basicValueTypes = [{
value: 'number',
label: 'Number'
} as const,{
value: 'boolean',
label: 'Boolean'
} as const];
type BasicValueTypes = typeof basicValueTypes[number]['value'];
// BasicValueTypes = "number" | "boolean"
However, I am still interested in knowing if the creation of the aforementioned ReadonlyItemArray
type is feasible?