I have a constant array of strings e.g.
const emojis = ['π', 'π', 'π', 'π', 'π£'] as const
And I want to have a type that contains a union of the indexes of that array e.g.
type emojiIndexes = IndexesOfArray<typeof emojis> // => 0 | 1 | 2 | 3 | 4
So that I don't allow using number
and use only the exact number of the indexes in the array
And if the array size e.g.
// changed from this
// const emojis = ['π', 'π', 'π', 'π', 'π£'] as const
// to this
const emojis = ['π', 'π', 'π'] as const // removed 2 emojis
Than, IndexesOfArray<typeof emojis>
would be 0 | 1 | 2
How can I create IndexesOfArray
that would create a union type with the indexes of the constant array?