Skip to content

Impossible 'body' field required in GET #1124

@gtrak

Description

@gtrak

Description

I'm seeing an issue where generated typescript types result in some impossible types:

Type error: Argument of type '{ params: { path: { id: string; }; }; }' is not assignable to parameter of type 'FetchOptions<{ parameters: { path: { id: string; }; }; responses: ...snipped
  Property 'body' is missing in type '{ params: { path: { id: string; }; }; }' but required in type '{ body: never; }'.

  10 |
  11 | async function exampleGet() {
> 12 |   const { data, error } = await get(`/v1/endpoint`, {
     |                                                                             ^
  13 |     params: { path: { id: "todo" } },
  14 |   });
  15 | }

I am able to work around it by adding a field body: "" as never, which seems to be forcing TS into the right path. body: undefined or body: null does not work either.

Reproduction

I used the latest versions of openapi-fetch, openapi-typescript, and an internal OpenAPI spec with only GETs in it.

Something relevant in the generated code seems to be:

export interface components {
...
  responses: never;
  parameters: never;
  requestBodies: never;  // <--
  headers: never;
  pathItems: never;
}

Expected result

I can work out the types in this scenario more easily.

Checklist

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopenapi-fetchRelevant to the openapi-fetch library

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions