I want to create a type based on an Object's keys and values, which are arrays of strings. This type should include all the possible string values like so:
const Actions = {
foo: ['bar', 'baz'],
}
# type generated from Actions should be:
type ActionsType = 'foo' | 'bar' | 'baz'
I have to keep Actions
as it needs to be passed to a method, therefore:
const Actions = {
foo: ['bar', 'baz'],
} as const
type ActionsType = keyof typeof Actions | typeof Actions[keyof typeof Actions][number]
Although generating the type correctly prevented me from passing Actions
to a method that expects Record<string, string[]>
because the keys and values became readonly.
Is there a way to generate the necessary type while still being able to use Actions
as a non-readonly Object?