I'm currently working on developing a function that utilizes a generic type to take in a function, an array of arguments for the function, and then apply them accordingly. However, I am facing an issue with TypeScript not correctly interpreting the args type.
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());
};
Upon attempting to use this function, I encountered the following error:
Argument of type '(rows: number, cols: number, startCell: Coordinates, endCell: Coordinates) => GridT[]' is not assignable to parameter of type '(...args: (number | Coordinates)[]) => GridT[]'