@@ -104,73 +104,33 @@ export type RequestOptions<T> = ParamsOption<T> &
104
104
fetch ?: ClientOptions [ "fetch" ] ;
105
105
} ;
106
106
107
+ export type ClientMethod < Paths extends { } , M > = <
108
+ P extends PathsWithMethod < Paths , M > ,
109
+ I extends MaybeOptionalInit < Paths [ P ] , M > ,
110
+ > (
111
+ url : P ,
112
+ ...init : I
113
+ ) => Promise < FetchResponse < Paths [ P ] [ M ] , I [ 0 ] > > ;
114
+
107
115
export default function createClient < Paths extends { } > (
108
116
clientOptions ?: ClientOptions ,
109
117
) : {
110
118
/** Call a GET endpoint */
111
- GET <
112
- P extends PathsWithMethod < Paths , "get" > ,
113
- I extends MaybeOptionalInit < Paths [ P ] , "get" > ,
114
- > (
115
- url : P ,
116
- ...init : I
117
- ) : Promise < FetchResponse < Paths [ P ] [ "get" ] , I [ 0 ] > > ;
119
+ GET : ClientMethod < Paths , "get" > ;
118
120
/** Call a PUT endpoint */
119
- PUT <
120
- P extends PathsWithMethod < Paths , "put" > ,
121
- I extends MaybeOptionalInit < Paths [ P ] , "put" > ,
122
- > (
123
- url : P ,
124
- ...init : I
125
- ) : Promise < FetchResponse < Paths [ P ] [ "put" ] , I [ 0 ] > > ;
121
+ PUT : ClientMethod < Paths , "put" > ;
126
122
/** Call a POST endpoint */
127
- POST <
128
- P extends PathsWithMethod < Paths , "post" > ,
129
- I extends MaybeOptionalInit < Paths [ P ] , "post" > ,
130
- > (
131
- url : P ,
132
- ...init : I
133
- ) : Promise < FetchResponse < Paths [ P ] [ "post" ] , I [ 0 ] > > ;
123
+ POST : ClientMethod < Paths , "post" > ;
134
124
/** Call a DELETE endpoint */
135
- DELETE <
136
- P extends PathsWithMethod < Paths , "delete" > ,
137
- I extends MaybeOptionalInit < Paths [ P ] , "delete" > ,
138
- > (
139
- url : P ,
140
- ...init : I
141
- ) : Promise < FetchResponse < Paths [ P ] [ "delete" ] , I [ 0 ] > > ;
125
+ DELETE : ClientMethod < Paths , "delete" > ;
142
126
/** Call a OPTIONS endpoint */
143
- OPTIONS <
144
- P extends PathsWithMethod < Paths , "options" > ,
145
- I extends MaybeOptionalInit < Paths [ P ] , "options" > ,
146
- > (
147
- url : P ,
148
- ...init : I
149
- ) : Promise < FetchResponse < Paths [ P ] [ "options" ] , I [ 0 ] > > ;
127
+ OPTIONS : ClientMethod < Paths , "options" > ;
150
128
/** Call a HEAD endpoint */
151
- HEAD <
152
- P extends PathsWithMethod < Paths , "head" > ,
153
- I extends MaybeOptionalInit < Paths [ P ] , "head" > ,
154
- > (
155
- url : P ,
156
- ...init : I
157
- ) : Promise < FetchResponse < Paths [ P ] [ "head" ] , I [ 0 ] > > ;
129
+ HEAD : ClientMethod < Paths , "head" > ;
158
130
/** Call a PATCH endpoint */
159
- PATCH <
160
- P extends PathsWithMethod < Paths , "patch" > ,
161
- I extends MaybeOptionalInit < Paths [ P ] , "patch" > ,
162
- > (
163
- url : P ,
164
- ...init : I
165
- ) : Promise < FetchResponse < Paths [ P ] [ "patch" ] , I [ 0 ] > > ;
131
+ PATCH : ClientMethod < Paths , "patch" > ;
166
132
/** Call a TRACE endpoint */
167
- TRACE <
168
- P extends PathsWithMethod < Paths , "trace" > ,
169
- I extends MaybeOptionalInit < Paths [ P ] , "trace" > ,
170
- > (
171
- url : P ,
172
- ...init : I
173
- ) : Promise < FetchResponse < Paths [ P ] [ "trace" ] , I [ 0 ] > > ;
133
+ TRACE : ClientMethod < Paths , "trace" > ;
174
134
} ;
175
135
176
136
/** Serialize query params to string */
0 commit comments