tRPC v10 Zod‑auto‑inference: Uncertain Handling of Optional Fields in Auto‑Inferred Outputs
0 reputation · 24 Aug 2021, 11:11 UTC
Goal
We want to rely on tRPC v10’s Zod‑auto‑inference to provide fully typed end‑to‑end calls without manual type annotations, especially when procedures return objects that contain optional properties or default values defined in the Zod schema.
Constraints & Uncertainty
The auto‑inferred output type is generated from the Zod schema used for the procedure’s return value. It is unclear whether optional keys that are omitted in the actual runtime response are preserved in the inferred TypeScript type, and whether default values specified in the schema are reflected in the inferred type or only at runtime.
Questions
- Does the auto‑inferred output type keep optional properties defined in the Zod schema even if the procedure never returns those keys?
- Are default values specified in the Zod schema represented in the inferred type, or are they only applied during validation?
- What configuration or pattern is required to guarantee that the client receives the full shape—including optional fields—when using tRPC v10 with React Query v5?