File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -156,21 +156,27 @@ import './fetch-polyfill'
156156- ` OpErrorType ` - Infer error type of an operation
157157- ` FetchArgType ` - Argument type of a typed fetch operation
158158- ` FetchReturnType ` - Return type of a typed fetch operation
159- - ` FetchErrorType ` - Return error type of a typed fetch operation
159+ - ` FetchErrorType ` - Error type of a typed fetch operation
160+ - ` TypedFetch ` - Fetch operation type
160161
161162``` ts
162163import { paths , operations } from ' ./petstore'
163164
164165type Arg = OpArgType <operations [' findPetsByStatus' ]>
165166type Ret = OpReturnType <operations [' findPetsByStatus' ]>
167+ type Err = OpErrorType <operations [' findPetsByStatus' ]>
166168
167169type Arg = OpArgType <paths [' /pet/findByStatus' ][' get' ]>
168170type Ret = OpReturnType <paths [' /pet/findByStatus' ][' get' ]>
171+ type Err = OpErrorType <paths [' /pet/findByStatus' ][' get' ]>
172+
173+ type FindPetsByStatus = TypedFetch <operations [' findPetsByStatus' ]>
169174
170175const findPetsByStatus = fetcher .path (' /pet/findByStatus' ).method (' get' ).create ()
171176
172177type Arg = FetchArgType <typeof findPetsByStatus >
173178type Ret = FetchReturnType <typeof findPetsByStatus >
179+ type Err = FetchErrorType <typeof findPetsByStatus >
174180` ` `
175181
176182Happy fetching! 👍
Original file line number Diff line number Diff line change 11{
22 "name" : " openapi-typescript-fetch" ,
33 "description" : " A typed fetch client for openapi-typescript" ,
4- "version" : " 1.1.1 " ,
4+ "version" : " 1.1.2 " ,
55 "engines" : {
66 "node" : " >= 12.0.0" ,
77 "npm" : " >= 7.0.0"
Original file line number Diff line number Diff line change 77 OpDefaultReturnType ,
88 OpErrorType ,
99 OpReturnType ,
10+ TypedFetch ,
1011} from '../src'
1112import { paths as paths2 } from './examples/stripe-openapi2'
1213import { paths as paths3 } from './examples/stripe-openapi3'
@@ -66,8 +67,13 @@ describe('infer', () => {
6667 } )
6768
6869 describe ( 'fetch' , ( ) => {
70+ type CreateLink = TypedFetch < Op2 >
71+
6972 const fetcher = Fetcher . for < paths2 > ( )
70- const createLink = fetcher . path ( '/v1/account_links' ) . method ( 'post' ) . create ( )
73+ const createLink : CreateLink = fetcher
74+ . path ( '/v1/account_links' )
75+ . method ( 'post' )
76+ . create ( )
7177
7278 type Arg = FetchArgType < typeof createLink >
7379 type Ret = FetchReturnType < typeof createLink >
You can’t perform that action at this time.
0 commit comments