Dev Helpers
← Back

Check whether a state is busy

Check whether a state is busy 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): s is Extract<State, { phase: "loading" }> =>
    s.phase === "loading")({ phase: "idle" }),
);

Sample output

false