-
-
Notifications
You must be signed in to change notification settings - Fork 578
Description
openapi-react-query version
0.5.0
Description
This is my hook: data is typed to be etiher the expected data or undefined.

But we experienced at 403 response that had no body (so content length 0) and then suddenly data was null. Causing an error further down in the code due to passing it to a function with default param. And they only work for undefined, not null.
Tracked it down to this line: https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-react-query/src/index.ts#L201
This should be data ?? undefined
for the types to be correct, or the types need to reflect null is possible. The first option is the intended behavior, no?
Even the test for this does not make sense if you see the type for data and the assertion to be null, not undefined.

I first assumed an error in openapi-fetch. But it correctly returns no data (so undefined) https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/src/index.js#L231
Reproduction
Can be reproduced by responding with no body and a non 2xx response. Log data.
Expected result
Data should always log undefined for any non 2xx response. It logs null.
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)