Skip to content

Commit b36125c

Browse files
authored
docs: contract router utilities (#184)
* docs: contract router utility * improve
1 parent 92faaf9 commit b36125c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

apps/content/docs/contract-first/define-contract.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,33 @@ export const contract = {
112112
},
113113
}
114114
```
115+
116+
## Utilities
117+
118+
### Infer Contract Router Input
119+
120+
```ts twoslash
121+
import type { contract } from './shared/planet'
122+
// ---cut---
123+
import type { InferContractRouterInputs } from '@orpc/contract'
124+
125+
export type Inputs = InferContractRouterInputs<typeof contract>
126+
127+
type FindPlanetInput = Inputs['planet']['find']
128+
```
129+
130+
This snippet automatically extracts the expected input types for each procedure in the router.
131+
132+
### Infer Contract Router Output
133+
134+
```ts twoslash
135+
import type { contract } from './shared/planet'
136+
// ---cut---
137+
import type { InferContractRouterOutputs } from '@orpc/contract'
138+
139+
export type Outputs = InferContractRouterOutputs<typeof contract>
140+
141+
type FindPlanetOutput = Outputs['planet']['find']
142+
```
143+
144+
Similarly, this utility infers the output types, ensuring that your application correctly handles the results from each procedure.

0 commit comments

Comments
 (0)