Is there a way to create a union type that strictly limits values to 'a', 'b', 'c' when using a list like
const list: string[] = ['a', 'b', 'c']
?
I know one method is:
const list = ['a', 'b', 'c'] as const;
type allowedValues = typeof list[number]
However, this approach makes the list
read-only and cannot be typed with string[]
. Is there a technique to constrain the values of list
while still maintaining its typing flexibility?