Hello I'm trying to make some function that looks like the redux toolkit createSlice.
const commandStore<T>(initial:T, commands: Record<string, Command<T, unknown[]) => {
const actions ={};
Object.entries(commands).forEach(([name, command])=>{
actions[name] = actionCreator(command.name);
});
return {action}
}
interface Command<T, TParams extends unknown[]> {
forward(state: T, ...args: TParams): T;
reverse(state: T,...args: TParams): T
name: string;
}
const actionCreator = <T extends unknown[]>(
command: string): ((...args: T)=>Action) => {
const createAction = (...args: T) => {
return {command, args}
}
return createAction
}```
I would like each command to have forward and reverse take the same parameters but different command could have different parameters.
I don't know how to define type to be able to return the TParams for each command