Skip to content

Commit dcbe311

Browse files
committed
readme: typed fetch
1 parent 4f984b9 commit dcbe311

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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
162163
import { paths, operations } from './petstore'
163164

164165
type Arg = OpArgType<operations['findPetsByStatus']>
165166
type Ret = OpReturnType<operations['findPetsByStatus']>
167+
type Err = OpErrorType<operations['findPetsByStatus']>
166168

167169
type Arg = OpArgType<paths['/pet/findByStatus']['get']>
168170
type Ret = OpReturnType<paths['/pet/findByStatus']['get']>
171+
type Err = OpErrorType<paths['/pet/findByStatus']['get']>
172+
173+
type FindPetsByStatus = TypedFetch<operations['findPetsByStatus']>
169174

170175
const findPetsByStatus = fetcher.path('/pet/findByStatus').method('get').create()
171176

172177
type Arg = FetchArgType<typeof findPetsByStatus>
173178
type Ret = FetchReturnType<typeof findPetsByStatus>
179+
type Err = FetchErrorType<typeof findPetsByStatus>
174180
```
175181
176182
Happy fetching! 👍

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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"

test/infer.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
OpDefaultReturnType,
88
OpErrorType,
99
OpReturnType,
10+
TypedFetch,
1011
} from '../src'
1112
import { paths as paths2 } from './examples/stripe-openapi2'
1213
import { 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>

0 commit comments

Comments
 (0)