@@ -115,6 +115,10 @@ interface User {
115115 name : string ;
116116}
117117
118+ interface ResponseHeaders {
119+ 'x-header' : string ;
120+ }
121+
118122// with default axios.AxiosResponse<T> result
119123
120124const handleUserResponse = ( response : axios . AxiosResponse < User > ) => {
@@ -162,6 +166,54 @@ axios.patch<User>('/user', { name: 'foo', id: 1 })
162166 . then ( handleUserResponse )
163167 . catch ( handleError ) ;
164168
169+
170+ // with custom response headers axios.AxiosResponse<T, any, H> result
171+
172+ const handleUserResponseWithCustomHeaders = ( response : axios . AxiosResponse < User , any , ResponseHeaders > ) => {
173+ console . log ( response . data . id ) ;
174+ console . log ( response . data . name ) ;
175+ console . log ( response . status ) ;
176+ console . log ( response . statusText ) ;
177+ console . log ( response . headers ) ;
178+ console . log ( response . config ) ;
179+ } ;
180+
181+ axios . get < User , axios . AxiosResponse < User , any , ResponseHeaders > > ( '/user?id=12345' )
182+ . then ( handleUserResponseWithCustomHeaders )
183+ . catch ( handleError ) ;
184+
185+ axios . get < User , axios . AxiosResponse < User , any , ResponseHeaders > > ( '/user' , { params : { id : 12345 } } )
186+ . then ( handleUserResponseWithCustomHeaders )
187+ . catch ( handleError ) ;
188+
189+ axios . head < User , axios . AxiosResponse < User , any , ResponseHeaders > > ( '/user' )
190+ . then ( handleUserResponseWithCustomHeaders )
191+ . catch ( handleError ) ;
192+
193+ axios . options < User , axios . AxiosResponse < User , any , ResponseHeaders > > ( '/user' )
194+ . then ( handleUserResponseWithCustomHeaders )
195+ . catch ( handleError ) ;
196+
197+ axios . delete < User , axios . AxiosResponse < User , any , ResponseHeaders > > ( '/user' )
198+ . then ( handleUserResponseWithCustomHeaders )
199+ . catch ( handleError ) ;
200+
201+ axios . post < User , axios . AxiosResponse < User , any , ResponseHeaders > > ( '/user' , { name : 'foo' , id : 1 } )
202+ . then ( handleUserResponseWithCustomHeaders )
203+ . catch ( handleError ) ;
204+
205+ axios . post < User , axios . AxiosResponse < User , any , ResponseHeaders > > ( '/user' , { name : 'foo' , id : 1 } , { headers : { 'X-FOO' : 'bar' } } )
206+ . then ( handleUserResponseWithCustomHeaders )
207+ . catch ( handleError ) ;
208+
209+ axios . put < User , axios . AxiosResponse < User , any , ResponseHeaders > > ( '/user' , { name : 'foo' , id : 1 } )
210+ . then ( handleUserResponseWithCustomHeaders )
211+ . catch ( handleError ) ;
212+
213+ axios . patch < User , axios . AxiosResponse < User , any , ResponseHeaders > > ( '/user' , { name : 'foo' , id : 1 } )
214+ . then ( handleUserResponseWithCustomHeaders )
215+ . catch ( handleError ) ;
216+
165217// (Typed methods) with custom response type
166218
167219const handleStringResponse = ( response : string ) => {
0 commit comments