Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,35 @@ export type ServiceMethodOptions = BaseServiceMethodOptions | undefined | never;

export type Segment = string | Record<string, string>;

export type ServiceMethod<O extends ServiceMethodOptions, R extends Response = Response> = (
methodOptions?: O & BaseServiceMethodOptions,
sdkOptions?: SDKOptions,
) => Promise<R>;
type HasRequiredMethodOptions<O extends ServiceMethodOptions> = Partial<O> extends O ? false : true;

export type ServiceMethod<O extends ServiceMethodOptions, R extends Response = Response> =
HasRequiredMethodOptions<O> extends true
? (methodOptions: O & BaseServiceMethodOptions, sdkOptions?: SDKOptions) => Promise<R>
: (methodOptions?: O & BaseServiceMethodOptions, sdkOptions?: SDKOptions) => Promise<R>;

export type ServiceMethodDynamicSegments<
S extends Segment,
O extends ServiceMethodOptions,
R extends Response = Response,
> = (
segments: S,
methodOptions?: O & {
query?: BaseServiceMethodOptions['query'];
headers?: BaseServiceMethodOptions['headers'];
},
sdkOptions?: SDKOptions,
) => Promise<R>;
> =
HasRequiredMethodOptions<O> extends true
? (
segments: S,
methodOptions: O & {
query?: BaseServiceMethodOptions['query'];
headers?: BaseServiceMethodOptions['headers'];
},
sdkOptions?: SDKOptions,
) => Promise<R>
: (
segments: S,
methodOptions?: O & {
query?: BaseServiceMethodOptions['query'];
headers?: BaseServiceMethodOptions['headers'];
},
sdkOptions?: SDKOptions,
) => Promise<R>;

/**
* Provides a type-safe union of a subset of object keys.
Expand Down