We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Instead of having all those enums with endpoints, maybe do something like this instead:
type Item = { id: number; name: string; }; type EndpointMap<Schema> = { '/v2/build': { type: { build: string } }, '/v2/items': { bulk: { id: number type: Item } }, '/v2/quaggans': { bulk: { id: string type: { id: string; name: string; } all: true } } } type GetEndpointsMatching<Schema, T> = { [X in keyof EndpointMap<Schema>]: EndpointMap<Schema>[X] extends T ? X: never }[keyof EndpointMap<Schema>] type SimpleEndpoints<Schema> = GetEndpointsMatching<Schema, { type: any }> type BulkEndpoints<Schema> = GetEndpointsMatching<Schema, { bulk: any }> type BulkEndpointSingleUrlMap<Schema> = { [Endpoint in BulkEndpoints<Schema> as `${Endpoint}/${EndpointMap<Schema>[Endpoint]['bulk']['id']}` | `${Endpoint}?id=${EndpointMap<Schema>[Endpoint]['bulk']['id']}`]: Endpoint } type BulkEndpointAllUrlMap<Schema> = { [Endpoint in BulkEndpoints<Schema> as `${Endpoint}?ids=all`]: EndpointMap<Schema>[Endpoint]['bulk'] extends { all: true } ? Endpoint : never } type BulkEndpointManyUrlMap<Schema> = { [Endpoint in BulkEndpoints<Schema> as `${Endpoint}?ids=${string}`]: Endpoint } type EndpointFromUrl<Url, Schema> = Url extends SimpleEndpoints<Schema> ? { endpoint: Url, type: EndpointMap<Schema>[Url]['type'] } : Url extends BulkEndpoints<Schema> ? { endpoint: Url, type: EndpointMap<Schema>[Url]['bulk']['id'][] } : Url extends keyof BulkEndpointSingleUrlMap<Schema> ? { endpoint: BulkEndpointSingleUrlMap<Schema>[Url], type: EndpointMap<Schema>[BulkEndpointSingleUrlMap<Schema>[Url]]['bulk']['type'] } : Url extends keyof BulkEndpointAllUrlMap<Schema> ? { endpoint: BulkEndpointAllUrlMap<Schema>[Url], type: EndpointMap<Schema>[BulkEndpointAllUrlMap<Schema>[Url]]['bulk']['type'][] } : Url extends keyof BulkEndpointManyUrlMap<Schema> ? { endpoint: BulkEndpointManyUrlMap<Schema>[Url], type: EndpointMap<Schema>[BulkEndpointManyUrlMap<Schema>[Url]]['bulk']['type'][] } : { endpoint: unknown, type: unknown }; type EndpointType<Url, Schema> = EndpointFromUrl<Url, Schema>['type']; type GetEndpointDefinition<Url, Schema> = EndpointFromUrl<Url, Schema>['endpoint'] extends keyof EndpointMap<Schema> ? EndpointMap<Schema>[EndpointFromUrl<Url, Schema>['endpoint']] : unknown;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Instead of having all those enums with endpoints, maybe do something like this instead:
The text was updated successfully, but these errors were encountered: