Use when writing TypeScript that branches on a value carrying a modeled state — a discriminated union, a status/kind/type tag, or any state-machine state — to choose behavior or a return value, or when adding a variant to such a union. Also when reaching for an if/else-if chain, an assertNever helper, or a lookup map to consume a tagged union.
Use when composing or chaining neverthrow Result / ResultAsync values — sequencing multi-step operations where each step can fail, recovering from a specific error, or deciding where to turn a Result into a plain value or HTTP response. Also when reaching for .match mid-pipeline, _unsafeUnwrap, isErr()+.value unwrapping, safeTry / yield*, or a try/catch around Result-returning code.
Use when converting a value to a number, string, or boolean in TypeScript, or annotating a primitive type — about to write Number(x), String(x), Boolean(x), unary +x, !!x, .filter(Boolean), or a : Number / : String / : Boolean type annotation.
Use when defining an error type, an error channel for a Result/ResultAsync, or a failure that crosses a throw / RxJS Observable / IPC boundary — anything you would otherwise model as an object union like `{ name: 'XError'; message: string }`.
Use when authoring or converting TypeScript — defining a type / interface / function signature, typing arguments or state, deciding between optional fields and a union, or about to reach for any, unknown, Record<string, unknown>, an index signature, or an as cast. The minimum modeling rules for making code TypeScript.
Use when branching keys off the prefix of a string (startsWith, namespaced name families like "file.", "edit.", "edit.image.") and the number of prefix branches is growing, when a prefix if-chain is becoming hard to test or extend per-family, or when adding several new prefix families to an existing dispatcher.
Convert `if`-based discriminated-value matching (HTTP status codes, event/action `type` fields, mode strings) to exhaustive `switch` statements. Use when refactoring existing code to the project style or when reviewing a file for `if (x === ...) / if (x !== ...)` clusters that should be flattened to switch.
Runbook for deploying and seeding the staging Cloudflare environment (stg.napochaan.com) with required env vars and recovery steps. Use when deploying to staging, running seed:export / seed:import / payload migrations against staging, or when hitting "Select which Cloudflare account" prompts (exit code 13) or "D1_ERROR: no such column". Triggers on "stg に deploy", "staging に反映", "seed:export to stg", "seed:import".