Skip to content

Commit

Permalink
fix: Allow mocking procedures with no return value (#36)
Browse files Browse the repository at this point in the history
* fix: Allow mocking procedures with no return value

* fix: Improve types
  • Loading branch information
danilofuchs authored Apr 22, 2024
1 parent b0812ae commit 6a9ebd8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export type ExtractInput<T extends ProcedureParams> = T extends ProcedureParams<
: never

export type ExtractOutput<T> = T extends Procedure<ProcedureType, infer ProcedureParams>
? ProcedureParams['_output_out'] extends DefaultBodyType
? ProcedureParams['_output_out'] extends void
? void
: ProcedureParams['_output_out'] extends DefaultBodyType
? ProcedureParams['_output_out']
: never
: never
Expand Down
9 changes: 9 additions & 0 deletions test/createTRPCMsw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ describe('proxy returned by createMswTrpc', () => {
>()
})

it('should interpret procedure without return as void', () => {
mswTrpc.noReturn.mutation(input => {
return
})
expectTypeOf(mswTrpc.noReturn.mutation).toEqualTypeOf<
(handler: (input: void) => PromiseOrValue<void>) => RequestHandler
>
})

describe('with merged routers', () => {
it('should expose property query on properties that match TRPC query procedures', () => {
expectTypeOf(nestedMswTrpc.users.userById.query).toEqualTypeOf<
Expand Down
1 change: 1 addition & 0 deletions test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const appRouter = t.router({

return input
}),
noReturn: t.procedure.mutation(() => {}),
})

const appRouterWithSuperJson = tWithSuperJson.router({
Expand Down

0 comments on commit 6a9ebd8

Please sign in to comment.