Struggling to configure the type correctly in this scenario.
I aim to define an object where each top-level key corresponds to a string from one union, with its value being a nested object consisting of keys from another union and values that can be strings from the first union (similar to a state machine).
For instance:
type Status = 'idle' | 'loading' | 'error' | 'view'
type Actions = 'search' | 'search_success' | 'search_failure'
const app = {
idle: {
search: 'loading'
},
loading: {
search_success: 'view',
search_fail: 'error',
},
error: {
search: 'loading'
}
view: {
search: 'loading'
}
}
My current typing attempts have been:
type States = { [key in Status]: { [key in Actions]: Status } };
However, this implementation is not functioning as expected. Can someone guide me on how I could potentially utilize utility types to allow the nested object key to selectively require values from the Actions type?
Thank you!