Dev Helpers
← Back

Build an accessible label per phase

Build an accessible label per phase 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(
  (
    {
      idle: "Ready",
      loading: "Please wait",
      ready: "Complete",
      error: "Failed",
    } satisfies Record<State["phase"], string>
  ).loading,
);

Sample output

Please wait