Course contentsShow
← TypeScript
Lesson 1573 of 1,79636. tRPC and End-to-End Type SafetyFree lesson

Inferring Mutation Input and Output Types

Type safety for mutation payloads and responses without manual type annotations on the client.

Inferring Mutation Input and Output Types

What you'll learn: How tRPC automatically infers TypeScript types for your mutation payloads and responses, eliminating manual type annotations on the client.


When you define a mutation procedure in your tRPC router, the framework captures both the input schema (what data you send) and the output type (what the mutation returns). The magic is that your client automatically knows these types without you writing them twice.

How Mutation Type Inference Works

Just like with queries, tRPC uses TypeScript's powerful type inference to extract mutation signatures from your router definition. When you call a mutation on the client, TypeScript already knows:

  • What shape of data the mutation expects as input
  • What type of data will be returned on success
  • Whether the input is optional or required

This happens because your AppRouter type flows through the typed client, and TypeScript traces back to the original mutation() definitions.

Accessing Mutation Types

You don't need to manually annotate types when calling mutations. The client hook or method already knows everything:

When you invoke a mutation, the input parameter is fully typed based on your Zod schema or input validator. The returned data is also typed according to what your mutation procedure returns. No manual type declarations needed—the types flow automatically from server to client.

Type Safety Without Duplication

The key insight: you define your mutation's contract once (input validation + return value), and that single definition becomes the source of truth for both ends. TypeScript infers the types, so you get autocomplete, error checking, and refactoring safety across your entire stack without writing separate interface definitions for the client.

Key Takeaway: tRPC infers mutation input and output types directly from your router definition, giving you complete type safety on mutation calls without any manual type annotations or duplication on the client side.