Skip to content

Instantly share code, notes, and snippets.

@bwlt
bwlt / debounce.ts
Last active Mar 17, 2020
A debounce function with type safety
View debounce.ts
export const MissingReturnValue = Symbol('MissingReturnValue')
export function debounce<Fn extends (...args: any[]) => any>(
fn: Fn,
ms: number
): (...args: Parameters<Fn>) => ReturnType<Fn> | typeof MissingReturnValue {
let debouncing = false
let lastReturnedValue:
| typeof MissingReturnValue
| ReturnType<Fn> = MissingReturnValue
@bwlt
bwlt / 2ad7gm.jpg
Last active May 23, 2018
milanojs - the good party 2018