Skip to content

#1580 causes type issue in MaybeOptionalInit #1584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mikestopcontinues opened this issue Mar 6, 2024 · 1 comment · Fixed by #1585
Closed

#1580 causes type issue in MaybeOptionalInit #1584

mikestopcontinues opened this issue Mar 6, 2024 · 1 comment · Fixed by #1585
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue!

Comments

@mikestopcontinues
Copy link
Contributor

MaybeOptionalInit now requires Paths[P] to be a complete record including every HttpMethod. However, routes rarely have every method. I think it should be defined as Partial<Record<HttpMethod, {}>> instead. The same with ClientMethod:

export type MaybeOptionalInit<
  P extends Partial<Record<HttpMethod, {}>>,
  M extends keyof P,
> =
  HasRequiredKeys<FetchOptions<FilterKeys<P, M>>> extends never
    ? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
    : [FetchOptions<FilterKeys<P, M>>];

export type ClientMethod<
  Paths extends Record<string, Partial<Record<HttpMethod, {}>>>,
  M extends HttpMethod,
> = <
  P extends PathsWithMethod<Paths, M>,
  I extends MaybeOptionalInit<Paths[P], M>,
>(
  url: P,
  ...init: I
) => Promise<FetchResponse<Paths[P][M], I[0]>>;
@drwpow
Copy link
Contributor

drwpow commented Mar 6, 2024

Ah yes you’re right! Sad that the internal type tests didn’t catch this. I’d accept a PR for this if you (or anyone else) is willing to add it

@drwpow drwpow added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue! good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project labels Mar 6, 2024
shirish87 added a commit to shirish87/browserstack-client that referenced this issue Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants