Skip to content

Default input typing for routes to use void not unknown #1135

@treehill05

Description

@treehill05

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:

  1. Always pass undefined as an argument (testMutate(undefined)), or
  2. 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 pingVoid

After (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

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions