export const files = ['a', 'b', 'c']
export type File = 'a' | 'b' | 'c'
How do I declare this File type without repeating the values like 'a', 'b', 'c'
.
export const files = ['a', 'b', 'c']
export type File = 'a' | 'b' | 'c'
How do I declare this File type without repeating the values like 'a', 'b', 'c'
.
You can use the typeof
with number
as index syntax. Note that as const
is needed in your array definition:
export const files = ['a', 'b', 'c'] as const;
export type File = typeof files[number];