Skip to content

Commit

Permalink
fix:types
Browse files Browse the repository at this point in the history
  • Loading branch information
prc5 committed Jul 6, 2024
1 parent a668b3d commit 535b4b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions packages/core/src/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
PayloadType,
RequestJSON,
RequestOptionsType,
ExtractRouteParams,
sendRequest,
RequestConfigurationType,
PayloadMapperType,
Expand Down Expand Up @@ -63,7 +62,7 @@ export class Request<
headers?: HeadersInit;
auth: boolean;
method: ExtractAdapterMethodType<Adapter>;
params: ExtractRouteParams<Endpoint> | NegativeTypes;
params: ExtractParamsType<this> | NegativeTypes;
data: PayloadType<Payload>;
queryParams: QueryParams | NegativeTypes;
options?: ExtractAdapterOptionsType<Adapter> | undefined;
Expand Down Expand Up @@ -180,7 +179,7 @@ export class Request<
return this.clone({ auth });
};

public setParams = <P extends ExtractRouteParams<Endpoint>>(params: P) => {
public setParams = <P extends ExtractParamsType<this>>(params: P) => {
return this.clone<HasData, P extends null ? false : true, HasQuery>({ params });
};

Expand Down Expand Up @@ -429,6 +428,7 @@ export class Request<
>(
configuration?: RequestConfigurationType<
Payload,
ExtractParamsType<this>,
QueryParams,
Endpoint,
ExtractAdapterOptionsType<Adapter>,
Expand All @@ -450,6 +450,7 @@ export class Request<
const json = this.toJSON();
const requestJSON: RequestConfigurationType<
Payload,
ExtractParamsType<this>,
QueryParams,
Endpoint,
ExtractAdapterOptionsType<Adapter>,
Expand Down Expand Up @@ -564,10 +565,10 @@ export class Request<
* ```
*/
public send: RequestSendType<this> = async (options?: RequestSendOptionsType<this>) => {
const { dispatcherType, ...rest } = options || {};
const { dispatcherType, ...configuration } = options || {};

const request = this.clone(rest);
return sendRequest(request, options);
const request = this.clone(configuration);
return sendRequest(request as this, options);
};
}

Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/request/request.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,14 @@ export type PayloadType<Payload> = Payload | NegativeTypes;

export type RequestConfigurationType<
Payload,
Params,
QueryParams,
GenericEndpoint extends string,
AdapterOptions extends Record<string, any>,
MethodsType = HttpMethodsType,
> = {
used?: boolean;
params?: ExtractRouteParams<GenericEndpoint> | NegativeTypes;
params?: Params | NegativeTypes;
queryParams?: QueryParams | NegativeTypes;
data?: PayloadType<Payload>;
headers?: HeadersInit;
Expand Down Expand Up @@ -223,7 +224,7 @@ export type FetchQueryParamsType<QueryParams, HasQuery extends true | false = fa
* If the request endpoint parameters are not filled it will throw an error
*/
export type FetchParamsType<Params, HasParams extends true | false> = Params extends NegativeTypes
? { params?: NegativeTypes }
? { params?: never }
: HasParams extends true
? { params?: NegativeTypes }
: { params: Params };
Expand Down

0 comments on commit 535b4b6

Please sign in to comment.