I'm looking to generate a type from an Object's keys, and values of arrays of strings. The type needs to represent all the possible strings, i.e.
const Actions = {
foo: ['bar', 'baz'],
}
# type generated from Actions to equal:
type ActionsType = 'foo' | 'bar' | 'baz'
I need to retain Actions as it's 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]
whilst generating the type correctly didn't allow me to pass Actions to a method expecting Record<string, string[]> as the keys and values became readonly.
How can I generate the required type whilst still being able to use Actions as a non-readonly Object?
foo: ['bar', 'baz'] as const, otherwise typescript will see the array as been dynamic.string[]therefore settingas conston the object, or the individual arrays generates the following error: "The type 'readonly ["bar", "baz"]' is 'readonly' and cannot be assigned to the mutable type 'string[]'"