Skip to main content

Checkpoint: Type-Safe Client Logic

intermediate20 min readLesson 91 of 143

Prove the typing mindset in runnable logic: runtime validators, a discriminated result pipeline, and generic narrowing helpers.

The sandbox runs JavaScript, so this checkpoint verifies the RUNTIME halves of the module's patterns โ€” the exact guards and shapes your TypeScript types will describe. If the logic is right, the types write themselves.

  1. isUser(v) โ€” a validator returning true only for well-formed user objects.
  2. parseWith(v, validator, fallback) โ€” validate-or-fallback wrapper.
  3. apiGet(kind) โ€” a fake client returning discriminated results and a handler that must check ok before touching data.

Types as the last module exam

TypeScript is only useful when it describes decisions, and this checkpoint asks you to make four: what unknown means at an API boundary, how a union makes invalid states unrepresentable, where a generic earns its parameter, and why a type guard beats an as cast. Each is a judgment call you will make daily on the job โ€” now you have made them under grading conditions.

Now practice

Mini Build: Typed API ModelModel a real API end-to-end at runtime: DTO validators, a discriminated result shape, and a typed-feel client wrapper.3 challenges ยท ยท ~22 min