Skip to content

Partial query params aren't optional #32

@TkDodo

Description

@TkDodo

I've copied the output of the standard PetStore example into a TypeScript playground.

At the end, I've created an api and tried to invoke findByStatus:

const api = createApiClient((method, url, params) =>
 fetch(url, { method, body: JSON.stringify(params) }).then((res) => res.json()),
);

api.get("/pet/findByStatus");

The error you'll see is:

Expected 2 arguments, but got 1.(2554)
input.tsx(316, 5): Arguments for the rest parameter 'params' were not provided.

When looking at the type of that function, config is indeed required:

(method) ApiClient.get<"/pet/findByStatus", Endpoints.get_FindPetsByStatus>(path: "/pet/findByStatus", config: {
    query: Partial<{
        status: "available" | "pending" | "sold";
    }>;
}): Promise<Schemas.Pet[]>

Screenshot 2024-03-19 at 16 44 18

However, running the same code in the typed-openapi playground shows the whole config as optional:

 const api = createApiClient((method, url, params) =>
   fetch(url, { method, body: JSON.stringify(params) }).then((res) => res.json()),
 );

 api.get("/pet/findByStatus");

Screenshot 2024-03-19 at 16 42 40

I'm not sure where that difference is coming from, but it seems that I have to pass { query: {} } to satisfy typescript right now and I don't think that is correct :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions