Skip to content
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

Client excessive routes #2200

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft

Client excessive routes #2200

wants to merge 12 commits into from

Conversation

RobinTail
Copy link
Owner

Address #2182 and #2183

@RobinTail RobinTail added enhancement New feature or request prevention labels Nov 20, 2024
Copy link

coveralls-official bot commented Nov 20, 2024

Coverage Status

coverage: 100.0%. remained the same
when pulling df68e92 on client-excessive-routes
into cae198d on master.

example/example.client.ts Outdated Show resolved Hide resolved
@RobinTail
Copy link
Owner Author

RobinTail commented Nov 21, 2024

I've got another idea...

type PathsForMethod<M extends Method> = keyof Response extends `${M} ${infer U}` ? U : never;

@RobinTail
Copy link
Owner Author

RobinTail commented Nov 21, 2024

I'm still struggling to figure out what exactly it should be.
The original statement was that it should be Typescript error.
Meanwhile, technically it's still possible to make unlisted requests, and the response could even be typed from errorHandler.

I need to decide on the goal:

  • should it be prevention of manual input mistakes
  • or should it be correctness

For type error it must be another input, like OctoKit — combines method+path. I see no other neat way.
For that could introduce another variant like strict client

can be like that

// rm extends from Input and Response
// this one changes to retain original behavior
export type Provider = <M extends Method, P extends Path>(
  method: M,
  path: P,
  params: `${M} ${P}` extends keyof Input ? Input[`${M} ${P}`] : Record<string, any>,
) => Promise<`${M} ${P}` extends keyof Response ? Response[`${M} ${P}`] : any>;

// this one new:
export type StrictProvider = <K extends keyof Input>(
  request: K,
  params: Input[K]
) => Promise<Response[K]>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request prevention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant