-
-
Notifications
You must be signed in to change notification settings - Fork 604
Closed
Description
I ran into this issue for an api call that may return 204.
If i check the returned data i expect it to be null
const { data } = await client.GET("/api/route/204");
if (data === null) {
// do something
}
const { field} = data;
But this library explicitly sets the data to be an empty object?!
openapi-typescript/packages/openapi-fetch/src/index.js
Lines 156 to 160 in 2a4b067
| // handle empty content | |
| // note: we return `{}` because we want user truthy checks for `.data` or `.error` to succeed | |
| if (response.status === 204 || response.headers.get("Content-Length") === "0") { | |
| return response.ok ? { data: {}, response } : { error: {}, response }; | |
| } |
Is there a reason for this?
This also breaks the type system, because it expects data to be the full object, null or undefined but not {}.
Metadata
Metadata
Assignees
Labels
No labels