Skip to content

client.GET response type is "never" with apis that only define a default response type #1862

Open
@ArenM

Description

@ArenM

Description

I'm writing a client for an api (which I don't control) that uses "default" as the type of the successful response. This isn't included in OkStatus which causes the response to be typed as never.

Reproduction

Generate a schema for this api and create a client from it.

const response = await client.GET("/versions", { params: {}});
console.log(response.data?.specifiedVersion);

This results in the following error: error TS2339: Property 'specifiedVersion' does not exist on type 'never'.

Expected result

No error generated (the code works when the error is ignored).

Checklist

  • I’m willing to open a PR (with feedback on whether to fix this in openapi-fetch or openapi-typescript)

Based on this https://spec.openapis.org/oas/v3.0.3#responses-object, I think using default for the success response type is allowed by the spec. I think this could either be fixed by a) adding "default" to OkStatus, or b) by adding logic to openapi-typescript to copy the default response type to a 2XX response if no other successful response type exists. I'm not sure what the unintended consequences of these would be.

Metadata

Metadata

Assignees

Labels

PRs welcomePRs are welcome to solve this issue!bugSomething isn't workingopenapi-fetchRelevant to the openapi-fetch library

Type

No type

Projects

Status

Accepted

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions