New paste Use cases Explore public pastes Text tools Developer API The Paste Library Security Sign in with Google
TYPESCRIPTExample pasteCreated 2026-08-022 viewsNo expiry

TypeScript discriminated union state

Raw New paste
typescriptRead-only
1
type RequestState<T> =
  | { status: "idle" }
  | { status: "loading" }
  | { status: "success"; data: T }
  | { status: "error"; message: string };

function label<T>(state: RequestState<T>): string {
  switch (state.status) {
    case "idle": return "Ready";
    case "loading": return "Loading…";
    case "success": return "Complete";
    case "error": return state.message;
  }
}
Report abuse

Paste details

Visibility
Public
Size
386 bytes
Protection
Standard link access
Retention
No automatic expiry

Share with confidence

Unlisted links are not searchable, but anyone with the URL can open them. Never paste live credentials or personal data.