Skip to content

Should MaybeOptionalInit really be an Array type? #1908

@smaspe

Description

@smaspe

Description

In the type definition of ClientMethod, init parameter is a rest parameter (...init), and its type is MaybeOptionalInit<Paths[P], M>, which is an Array.

However, when this type is used, in createClient, only the first element is ever used in the return value.

For example:

    /** Call a POST endpoint */
    POST(url, init) {
      return coreFetch(url, { ...init, method: "POST" });
    },

This is because init in the implementation of POST (and of all the other methods) is not a rest parameter, and so it only captures the first value.

The MaybeOptionalInit is actually always an array of 1 element (and the type is defined as such). However, when the type is captured, it's not obvious in all contexts.

Reproduction

It's a type issue, so it nothing happens at runtime.

Expected result

MaybeOptionalInit looks like it could be a simple value, not an Array. It would make it easier to capture the types of the parameters when wrapping the Client object into a decorator.

Checklist

Metadata

Metadata

Assignees

No one assigned

    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