Skip to content

Commit d85ed87

Browse files
author
Mateusz Tkacz
committed
chore: further type simplification
1 parent decce02 commit d85ed87

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/app/api-contracts/src/route-contract/defineRouteContract.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,22 @@ type Exactly<T, U> = T & {
5252
[K in keyof T]: K extends keyof U ? T[K] : never
5353
}
5454

55-
type TypedPath<T extends z.ZodType | undefined> = {
56-
requestPathParamsSchema?: T
55+
type TypedPathRouteContract<T extends z.ZodType | undefined> = Omit<
56+
RouteContract,
57+
'pathResolver' | 'requestPathParamsSchema'
58+
> & {
5759
pathResolver: RoutePathResolver<InferSchemaOutput<T>>
60+
requestPathParamsSchema?: T
5861
}
5962

6063
export const defineRouteContract = <
6164
PathParamsSchema extends z.ZodType | undefined,
62-
TypedPathContract extends Omit<RouteContract, 'pathResolver'> & TypedPath<PathParamsSchema>,
63-
const Contract extends TypedPathContract,
65+
const Contract extends TypedPathRouteContract<PathParamsSchema>,
6466
>(
65-
route: Exactly<Contract, TypedPathContract> & TypedPath<PathParamsSchema>,
66-
): Contract => route
67+
contract: Exactly<Contract, TypedPathRouteContract<PathParamsSchema>> & {
68+
requestPathParamsSchema?: PathParamsSchema
69+
},
70+
): Contract => contract
6771

6872
export const mapRouteContractToPath = (routeConfig: RouteContract): string => {
6973
if (!routeConfig.requestPathParamsSchema) {

0 commit comments

Comments
 (0)