-
-
Couldn't load subscription status.
- Fork 92
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Describe the feature
Problem
Currently, when defining procedures without an explicit .input() call, the default input schema is Schema<unknown, unknown>, which causes TypeScript errors when calling procedures that don't require input.
Example:
// playgrounds/next/src/routers/ping.ts
export const ping = pub.output(PingSchema).handler(() => 'pong')
export const pingVoid = pub.input(PingVoidSchema).handler(() => 'pong')// playgrounds/next/src/app/orpc-mutation.tsx
const { mutate: testMutate } = useMutation(orpc.ping.run.mutationOptions())
const { mutate: testVoidMutate } = useMutation(orpc.ping.runVoid.mutationOptions())
useCallback(() => {
testMutate() // ❌ Type error! Must provide argument even though input is unused
testMutate(undefined) // ✅ Works but awkward
testVoidMutate() // ✅ Works because explicit z.void() was specified
}, [testMutate, testVoidMutate])This forces developers to either:
- Always pass
undefinedas an argument (testMutate(undefined)), or - Explicitly add
.input(z.void())to every procedure without input
Both approaches add unnecessary boilerplate and hurt developer experience.
Proposed Solution
Change the default input schema from Schema<unknown, unknown> to Schema<void, void> for both os and oc builders.
Before:
// Must explicitly specify z.void() or risk type errors
export const ping = pub.output(PingSchema).handler(() => 'pong')
export const pingVoid = pub.input(z.void()).handler(() => 'pong')
// Usage requires explicit undefined or no arguments depending on schema
testMutate(undefined) // Required for ping
testVoidMutate() // Works for pingVoidAfter (with this feature):
// Both work the same way - z.void() is implicit by default
export const ping = pub.output(PingSchema).handler(() => 'pong')
export const pingVoid = pub.output(PingSchema).handler(() => 'pong')
// Usage is consistent - no arguments needed
testMutate() // ✅ Works!
testVoidMutate() // ✅ Works!Additional information
- Would you be willing to help implement this feature?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request