Build the safeguards
Eight explained steps, tradeoffs, pitfalls and a checkpoint before moving on.
Read the tutorialHow-to / First result to independent work
Start with the result you can see, then choose how far into the implementation you want to go.
Run one failure and one safeguarded version. Read tutorial Steps 1–4. Write down the input, the violated rule, the decision that enforces it, and the remaining limit. Keep that four-part explanation beside the code.
Show the malformed input first. Explain why the assertion compiled, where validation belongs, how the union changes the interface, and why cancellation and response ordering are separate concerns.
Download and extract the matching source. Begin with GETTING_STARTED.md. The included preview serves the prebuilt browser application on your own computer. Follow the eight tutorial steps, then run the native checks. The public source viewer is read-only; local source files are yours to edit.
python preview.py
# Open the loopback address printed by the preview.
# Stop the preview with Ctrl+C.Use the language-specific instructions below before rebuilding. Serve the application over HTTP; opening an HTML file directly does not provide the module and WebAssembly environment used by the preview.
# With Node 24 and pnpm available:
pnpm install --frozen-lockfile
pnpm run typecheck
pnpm run build
pnpm testIndependent challenge
Add currency validation, a rejected state and a retry action. Keep the previous response from committing after a reset. Explain which invariants are enforced at compile time and which require runtime decisions.
Write the expected behavior before changing the implementation. Keep the original failure as a regression case. Explain the tradeoff you accepted and the result that would make you reconsider it.
The download includes a recording script, a test matrix and a revision record. Use captions and keep the code readable at the target viewing size.
References support the language and runtime concepts. The lesson, scenarios and explanations are original Zyel Lab material.
Keep exploring
Eight explained steps, tradeoffs, pitfalls and a checkpoint before moving on.
Read the tutorialChoose a pattern and an environment for the problem you actually have.
Compare approachesA beginner route, a local setup and an extension challenge.
Open the how-to guideLab discussion / TypeScript Boundary Lab
Ask about the code, compare an approach, or describe an edge case. Reader comments are reviewed before publication.
Code walkthrough
These short excerpts connect the lab’s behavior to its implementation. Each example links to the full tutorial step for its context, tradeoffs and checkpoint. Names and dependencies belong to that source; the excerpts are not standalone programs.
Read parseQuote in the code viewer. It first checks object shape, then identifier formats, then safe whole-number cents. It returns a discriminated success-or-error result. It also constructs a new object, so unrelated incoming properties do not silently become domain state. Validation is a business boundary: zero is allowed here, a negative price is not.
export type Result<T> =
| { ok: true; value: T }
| { ok: false; error: string };
Both IDs are strings at runtime, but their meanings differ. Brand<string, Name> separates CustomerId and QuoteId in checked code. The brand is introduced only after the validator checks the prefix. The negative type tests deliberately try assigning one ID type to the other. They use @ts-expect-error so a later change that removes the distinction fails type checking.
type Brand<T, Name extends string> =
T & { readonly __brand: Name };
type CustomerId = Brand<string, "CustomerId">;
Read State and transition. An approved state contains a verified quote and an approver. Idle does not carry those fields. The approve transition still checks the current state and a nonempty approver because callers can request an inappropriate action at runtime. A tagged union makes the data contract precise; the transition function enforces workflow rules.
type State =
| { status: "idle" }
| { status: "ready"; quote: Quote }
| { status: "approved"; quote: Quote; approvedBy: string };