Worked solutions 03 · Data boundaries
A. Predict the parser
The empty array succeeds with zero records. The wrapper object fails the outer-array check. Duplicate valid IDs fail uniqueness. Negative places fail the capacity rule. The supplied parser also compares the parsed UTC date back to the original date text, so 2026-02-31 fails instead of being accepted after calendar normalization. These are runtime observations distinct from compile-time shape checks.
For checkpoint 03, replace the parsed input with a valid JavaScript expression such as [] or { events: [] } in a copied project. Breaking an imported JSON file’s syntax prevents Vite from building it; use checkpoint 08 to observe fetched malformed JSON as a recoverable runtime failure.
B. Repair a false guarantee
Use const value: unknown = await response.json(); const events = parseEvents(value); after checking response.ok. The assertion in the flawed version creates no runtime check. Malformed JSON rejects while reading the body. A parseable object of the wrong shape reaches parseEvents and is rejected there. Both should be caught by the loader’s failure path, but keeping separate tests reveals which boundary was exercised.
C. Transfer
Add durationMinutes?: number to the copied model. Before constructing the returned record, reject a present value unless typeof is number, Number.isInteger is true, and the value lies inclusively between 15 and 240. Copy the optional property only when supplied. Absence, 15 and 240 pass; 14, 241, 30.5 and “30” fail. The UI can use event.durationMinutes === undefined ? 'Duration not supplied' : ... to distinguish absence from a value.
The type annotation catches incorrect authored values; the runtime branch catches unknown data. A check such as if (durationMinutes) is weaker because truthiness is not the domain contract. Keep the original shared model unchanged unless deliberately updating every dependent checkpoint.