just-debounce-it
Version:
return a debounced function
28 lines (22 loc) • 615 B
TypeScript
// Definitions by: Aziz Khambati <https://github.com/azizhk>
type ArgumentTypes<F extends Function> = F extends (...args: infer A) => any ? A : never;
type MethodTypes = {
cancel: () => void;
flush: () => void;
}
export default debounce;
declare function debounce<T extends Function>(
fn: T,
wait?: 0,
callFirst?: boolean
): T & MethodTypes;
declare function debounce<T extends Function>(
fn: T,
wait: number,
callFirst: true
): T & MethodTypes;
declare function debounce<T extends Function>(
fn: T,
wait: number,
callFirst?: false
): ((...args: ArgumentTypes<T>) => void) & MethodTypes;