Skip to content

Commit 2eebbe7

Browse files
committed
fix(api): Config object is optional on abstracted method functions
Fix types for `api.get` and abstracted config object
1 parent 839f934 commit 2eebbe7

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/api/src/index.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,35 @@ const api = async <T extends Config>(config: T): Promise<Response & {
6161
throw error;
6262
};
6363

64-
const get = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => api({
65-
...config,
66-
method: 'get',
67-
endpoint,
68-
});
64+
type AbstractedConfig = Omit<Config, 'endpoint' | 'method'>;
65+
66+
const get = <E extends Endpoint, C extends AbstractedConfig>(
67+
endpoint: E,
68+
config?: C,
69+
): Promise<Response & {
70+
config: Config,
71+
data: ResponseBody<{ endpoint: E }>,
72+
}> => api({ ...config, endpoint });
6973

70-
const post = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => api({
74+
const post = (endpoint: Endpoint, config?: AbstractedConfig) => api({
7175
...config,
7276
method: 'post',
7377
endpoint,
7478
});
7579

76-
const put = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => api({
80+
const put = (endpoint: Endpoint, config?: AbstractedConfig) => api({
7781
...config,
7882
method: 'put',
7983
endpoint,
8084
});
8185

82-
const patch = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => api({
86+
const patch = (endpoint: Endpoint, config?: AbstractedConfig) => api({
8387
...config,
8488
method: 'patch',
8589
endpoint,
8690
});
8791

88-
const del = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => api({
92+
const del = (endpoint: Endpoint, config?: AbstractedConfig) => api({
8993
...config,
9094
method: 'delete',
9195
endpoint,

0 commit comments

Comments
 (0)