FG
💻 Software🌐 Web & Full-Stack

feat: Define a router independently of its implementation

Freshabout 1 year ago
Mar 14, 20260 views
Confidence Score80%
80%

Problem

Describe the feature you'd like to request See example repo (https://github.com/rhinodavid/trpc-server-definition) for all the details My request is similar to the one @iduuck wrote about in https://github.com/trpc/trpc/issues/3496#issuecomment-1425705704. tldr: One should not need the server implementation in order to get a typed client. Currently this is not possible (I don't think -- I"m pretty new here) -- all the examples I've seen create the client using the `typeof` the AppRouter definition. Describe the solution you'd like to see My proposed solution is to create utility types to define the router type. Usage would look like this: [code block] In the server implementation, you'd enforce that the server satisfies the interface: [code block] Then the client is typed with the interface: [code block] The example repo has a complete(?) working PoC. Describe alternate solutions Another possible solution is a codegen step as described in https://github.com/trpc/trpc/issues/3496#issuecomment-1425705704. The pro of this solution is it keeps the existing pattern of [implement router] -> [extract interface]. Some might prefer this, but after a long time using gRPC/stubby I'm more used to the [define interface] -> [implement router] pattern. This pattern is better for large organizations where multiple teams might need to debate and agree on the interface. The con of the solution is codegen can be finicky. It also doesn't easily solve the workspace organization probl

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
76% confidence100% success rate4 verificationsLast verified Mar 14, 2026

Solution: feat: Define a router independently of its implementation

Low Risk

Separate trpc definitions and implementations should be a core aspect of any RPC protocol given that client / server generation is a fundamental part of this library. Consider for example a monorepo, where multiple services need to generate clients from a trpc router.... you don't want to import the entire service definition as a dependency.

76

Trust Score

4 verifications

100% success
  1. 1

    Separate trpc definitions and implementations should be a core aspect of any RPC

    Separate trpc definitions and implementations should be a core aspect of any RPC protocol given that client / server generation is a fundamental part of this library. Consider for example a monorepo, where multiple services need to generate clients from a trpc router.... you don't want to import the entire service definition as a dependency.

Validation

Resolved in trpc/trpc GitHub issue #3798. Community reactions: 7 upvotes.

Verification Summary

Worked: 4
Partial: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

trpctypescriptapi