Closed
Description
The following snippet of code should be valid, as per the README:
import createClient from "openapi-fetch";
import type { paths } from "./petstore"; // npx openapi-typescript https://petstore3.swagger.io/api/v3/openapi.yaml -o petstore.d.ts
const client = createClient<paths>();
client.POST("/store/order", {
body: {
id: 0,
},
})
However, it is failing with:
error TS2345: Argument of type '{ body: {}; }' is not assignable to parameter of type '{ params: { query?: never; header?: never; path?: never; cookie?: never; }; } & { body?: { id?: number; petId?: number; quantity?: number; shipDate?: string; status?: "placed" | "approved" | "delivered"; complete?: boolean; }; } & { ...; } & Omit<...> & { ...; }'.
Property 'params' is missing in type '{ body: {}; }' but required in type '{ params: { query?: never; header?: never; path?: never; cookie?: never; }; }'.
6 client.POST("/store/order", {
~
7 body: {
~~~~~~~~~~~
...
9 },
~~~~~~
10 })
~
node_modules/openapi-fetch/dist/index.d.ts:87:9
87 : { params: T["parameters"] }
~~~~~~
'params' is declared here.
If I change it to:
import createClient from "openapi-fetch";
import type { paths } from "./petstore"; // npx openapi-typescript https://petstore3.swagger.io/api/v3/openapi.yaml -o petstore.d.ts
const client = createClient<paths>();
client.POST("/store/order", {
params: {},
body: {
id: 0,
},
})
the error goes away.
Is this a recent regression? I don't remember it doing this before. I'm using typescript 5.5.4
, openapi-fetch 0.10.2
, and openapi-typscript 7.1.0
.
my tsconfig.json
:
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"noImplicitAny": true,
},
"files": [
"test.ts"
]
}
Checklist
- I’m willing to open a PR (see CONTRIBUTING.md)