Skip to content

Commit

Permalink
enhance: Add optional generic for fetch return value in shape types (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kmartinezmedia committed Apr 3, 2020
1 parent bb75c15 commit 280fa3d
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/rest-hooks/src/resource/shapes.ts
Expand Up @@ -8,10 +8,11 @@ export interface FetchShape<
Params extends Readonly<object> = Readonly<object>,
Body extends Readonly<object | string> | void =
| Readonly<object | string>
| undefined
| undefined,
Response = any
> {
readonly type: 'read' | 'mutate' | 'delete';
fetch(params: Params, body: Body): Promise<any>;
fetch(params: Params, body: Body): Promise<Response>;
getFetchKey(params: Params): string;
readonly schema: S;
readonly options?: FetchOptions;
Expand All @@ -32,20 +33,27 @@ export interface MutateShape<
Params extends Readonly<object> = Readonly<object>,
Body extends Readonly<object | string> | void =
| Readonly<object | string>
| undefined
> extends FetchShape<S, Params, Body> {
| undefined,
Response extends object | string | number | boolean =
| object
| string
| number
| boolean
> extends FetchShape<S, Params, Body, Response> {
readonly type: 'mutate';
fetch(
params: Params,
body: Body,
): Promise<object | string | number | boolean>;
fetch(params: Params, body: Body): Promise<Response>;
}

/** For retrieval requests */
export interface ReadShape<
S extends Schema,
Params extends Readonly<object> = Readonly<object>
Params extends Readonly<object> = Readonly<object>,
Response extends object | string | number | boolean =
| object
| string
| number
| boolean
> extends FetchShape<S, Params, undefined> {
readonly type: 'read';
fetch(params: Params): Promise<object | string | number | boolean>;
fetch(params: Params): Promise<Response>;
}

0 comments on commit 280fa3d

Please sign in to comment.