Six tasks with hidden checks: ASP.NET validation and 404 handling, C# cancellation, and TypeScript overlap, deep merge, and debounce fixes, checked with dotnet run and node --test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 lines
440 B
TypeScript
16 lines
440 B
TypeScript
export function debounce<T extends unknown[]>(fn: (...args: T) => void, wait: number): (...args: T) => void {
|
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
let pending: T | undefined;
|
|
return (...args: T) => {
|
|
if (pending === undefined) {
|
|
pending = args;
|
|
}
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => {
|
|
const call = pending as T;
|
|
pending = undefined;
|
|
fn(...call);
|
|
}, wait);
|
|
};
|
|
}
|