Skip to main content

Type-Safe Client Logic Check

Challenge on lesson: Checkpoint: Type-Safe Client Logic

Implement three typing-discipline helpers: 1. isUser(v) — RETURN true only when v is an object (not null, not array) with a string id, string email containing "@", and optional string name (absent or string). 2. parseWith(v, validator, fallback) — RETURN { ok: true, value } when validator(v) is true, else { ok: false, fallback }. 3. handleApi(result)result is { ok: true, data } or { ok: false, status }. RETURN the data string when ok, else "HTTP " + status. It must never read .data on a failure object.

Difficulty: intermediate

Back to lesson: Checkpoint: Type-Safe Client Logic