Junior — Senior
Determining the payload type based on the value of action.type
livecode
Task condition
It is necessary to describe the Action type so that the type of the payload property is automatically inferred from the specific value of action.type.
enum ActionType {
one = "one",
two = "two",
}
const reducer = <T extends ActionType>(
state: State,
action: Action<T>,
): State
action = { type, payload }
type Action = ?
The task requires using TypeScript features (generics, conditional types, mapping) to bind the correct payload type to each ActionType variant.