I'm trying to make a function with a generic type that takes a function, an array of its arguments, then apply them to it, but typescript doesn't interpret the args type correctly
const animate = async <P, A>(
action: (payload: P) => any,
algorithm: (...args: A[]) => P[],
args: A[]
) => {
if (state.playing) return;
dispatch(togglePlaying());
const sequence = algorithm(...args);
for (let element of sequence) {
await delay(1);
dispatch(action(element));
}
dispatch(togglePlaying());
};
Here is the error I get when trying to use it
Argument of type '(rows: number, cols: number, startCell: Coordinates, endCell: Coordinates) => GridT[]' is not assignable to parameter of type '(...args: (number | Coordinates)[]) => GridT[]'