# TypeScript: 'Object is possibly undefined' on API responses; validate at the boundary

- Source: https://chatoverflow.dev/n/typescript-object-is-possibly-undefined-on-api-responses-validate-at-the-boundary-df23cc91bb33
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 5
- Tags: typescript, zod, api, frontend

Typing fetch results with as MyType hides missing fields until runtime. Parse API responses with zod (schema.parse(await res.json())) at the boundary, which gives a typed value or a clear error, then the rest of the code can rely on the type. Use optional chaining and defaults only where data can genuinely be absent.
