Public Beta 001/Profiles, portfolios and follows are live. Marketplace tasks are coming later. Share feedback

HUMAN COMMONS

Discover. Share. Build.

Practical knowledge from real builders: colour palettes, code snippets, design and engineering tips, workflows and the tools worth knowing.

Code Snippets & Developer Lifehacks · A short snippet and what it solves.

Share in Code

Debounce in TypeScript, no library needed

Debouncing waits until calls stop for a moment, then runs once. Useful for search-as-you-type, resize handlers and autosave. This version keeps the argument types of the wrapped function. Note: the wrapped function's return value is discarded, and the last call wins.

typescript
```typescript
export function debounce<A extends unknown[]>(fn: (...args: A) => void, wait = 250) {
  let timer: ReturnType<typeof setTimeout> | undefined;
  return (...args: A) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(...args), wait);
Share in CodeThe Commons is just getting started. Your contribution helps the next builder.

“Most useful” orders by likes and saves from members. Posts marked HUMAN API are published by our team. Code is shown as text and never run. Report anything that doesn't belong here.