Skip to content
Tool · SandboxVerified 2 Nov 2026

Prompt-to-code sandbox

Pick a prompt, pick a language, and see the kind of code a well-specified prompt produces. Notice how each prompt's constraints show up directly in the output.

Prompt

Write a generic debounce function. It delays calls until `waitMs` has passed with no new call, supports cancel(), and preserves argument types. No dependencies.

Explicit constraintsAPI shape statedNo-dependency rule
debounce.ts — generated by Copilot
export interface Debounced<A extends unknown[]> {
  (...args: A): void;
  cancel(): void;
}

export function debounce<A extends unknown[]>(
  fn: (...args: A) => void,
  waitMs: number,
): Debounced<A> {
  let timer: ReturnType<typeof setTimeout> | undefined;

  const debounced = (...args: A) => {
    if (timer) clearTimeout(timer);
    timer = setTimeout(() => {
      timer = undefined;
      fn(...args);
    }, waitMs);
  };

  debounced.cancel = () => {
    if (timer) clearTimeout(timer);
    timer = undefined;
  };

  return debounced;
}

Representative output written and reviewed for this site. Real Copilot output varies by model and context — always review generated code.