File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -61,31 +61,35 @@ const api = async <T extends Config>(config: T): Promise<Response & {
61
61
throw error ;
62
62
} ;
63
63
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 } ) ;
69
73
70
- const post = ( endpoint : Endpoint , config : Exclude < Config , 'method' > ) => api ( {
74
+ const post = ( endpoint : Endpoint , config ?: AbstractedConfig ) => api ( {
71
75
...config ,
72
76
method : 'post' ,
73
77
endpoint,
74
78
} ) ;
75
79
76
- const put = ( endpoint : Endpoint , config : Exclude < Config , 'method' > ) => api ( {
80
+ const put = ( endpoint : Endpoint , config ?: AbstractedConfig ) => api ( {
77
81
...config ,
78
82
method : 'put' ,
79
83
endpoint,
80
84
} ) ;
81
85
82
- const patch = ( endpoint : Endpoint , config : Exclude < Config , 'method' > ) => api ( {
86
+ const patch = ( endpoint : Endpoint , config ?: AbstractedConfig ) => api ( {
83
87
...config ,
84
88
method : 'patch' ,
85
89
endpoint,
86
90
} ) ;
87
91
88
- const del = ( endpoint : Endpoint , config : Exclude < Config , 'method' > ) => api ( {
92
+ const del = ( endpoint : Endpoint , config ?: AbstractedConfig ) => api ( {
89
93
...config ,
90
94
method : 'delete' ,
91
95
endpoint,
You can’t perform that action at this time.
0 commit comments