-
-
Notifications
You must be signed in to change notification settings - Fork 266
Open
Labels
bug 🔥Something isn't workingSomething isn't workingclientClient package relatedClient package related
Description
The RequestResult type results in a lack of type safety when the return value of methods for 204 endpoints (where data: undefined).
Reproducible example or configuration
Create openapi.yaml with:
openapi: 3.1.0
paths:
"/":
get:
operationId: example__get
responses:
'204': {}
'404':
content:
application/json:
schema:
properties:
message:
type: string
title: Message
type: object
required:
- messageGenerate the client with npx @hey-api/openapi-ts -i ./openapi.yaml -o src/client.
Create tsconfig.json with:
{
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"types": ["jasmine"]
}
}Run npm add @types/jasmine.
Create src/demo.ts with:
import * as client from "./client/sdk.gen";
spyOn(client, "exampleGet").and.returnValue(
Promise.resolve({
data: undefined,
error: 123, // no type error :(
request: new Request(""),
response: new Response(),
}),
);Observe that the error value results in no type error even though it should. This is caused by the ThrowOnError extends true conditional type in the definition of the RequestResult type. Removing the conditional (or replacing ThrowOnError extends true with false extends true) makes the code produce the desired type error.
It would be nice if there was an option to not generate the ThrowOnError generics since we never use them.
Metadata
Metadata
Assignees
Labels
bug 🔥Something isn't workingSomething isn't workingclientClient package relatedClient package related