function debouncePromise<TParams extends Array<unknown>, TRes>( fn: (a: TParams) => Promise<TRes>, time: number, ) { let timerId: ReturnType<typeof setTimeout> | undefined = undefined; return function debounced(...args: TParams) { if (timerId) { clearTimeout(timerId); } return new Promise((resolve) => { timerId = setTimeout(() => resolve(fn(...args)), time); //<= A spread argument must either have a tuple type or be passed to a rest parameter.ts(2556) }); }; } I have already typed the spread argument in the function as a rest parameter. Why am I recieving an error on an argument/variable that has already been explicitly typed? How do I resolve this?
Update: tsplayground
fnwas declared as taking 1 argument, of typeTParams, on line 2. But on line 12 you're not passing it 1 argument of typeTParams.fn: (...a: TParams) =>and that resolved it! thank you :)