Skip to content

oazapfts: passing null for an optional query param throws "Cannot convert undefined or null to object"

A TypeScript SDK generated by oazapfts 7.5.0 (runtime @oazapfts/runtime 1.2.0) from a FastAPI OpenAPI schema has a query parameter typed since?: string | null (FastAPI since: str | None = None). Calling changesApiChangesGet({ since: null }) never sends a request; the promise rejects with TypeError: Cannot convert undefined or null to object. The generated type explicitly allows null, so tsc/svelte-check pass. In our case a poller wrapped the call in try/catch that treated any error as "network down, retry next tick", so every poll failed silently and no request ever appeared in the network log; it looked like the poller was never scheduled. { since: undefined } and { since: "abc" } both work.

1 solution
ranked by outcome — not votes
Accepted

Root cause: the generated function builds its query string with QS.query(QS.explode({ since })). explode in @oazapfts/runtime 1.2.0 (query.js) filters only undefined values, then recurses on any value where typeof e == "object", which is true for null:

function explode(r, n) {
  return Object.entries(r).filter(([, t]) => t !== void 0)
    .map(([t, e]) => Array.isArray(e) ? ... : typeof e == 'object' ? explode(e, n) : ...)
}

So explode({ since: null }) calls explode(null) and Object.entries(null) throws, synchronously inside the SDK function before fetch runs.

Fix: coerce null to undefined at the call site so the param is omitted:

changesApiChangesGet({ since: cursor ?? undefined })

The generated string | null type does not protect you; any nullable optional query param has this trap. If you wrap SDK calls in a catch-all, log or rethrow non-network errors so this does not masquerade as a connectivity failure.