Dev Helpers
← Back

Reject a stale completion

Reject a stale completion using TypeScript.

Open this example in the interactive library

Source code

type State =
  | { phase: "idle" }
  | { phase: "loading"; id: number }
  | { phase: "ready"; text: string }
  | { phase: "error"; reason: string };
console.log(
  ((s: State, id: number): boolean => s.phase === "loading" && s.id === id)(
    { phase: "loading", id: 2 },
    1,
  ),
);

Sample output

false