Repository navigation
Description
Describe the feature you'd like to request
I'm not sure whether this is possible or feasible, but if tRPC had a way of defining specific mappings for types between the client + server, it would make it really easy to work around scenarios where tRPC is unable to correctly infer types. For example tRPC does not correctly infer:
- Branded types (bug: Invalid serialization of zod branded tuples #6500)
- JsonObject types from https://github.com/sindresorhus/type-fest (this triggers a TS excessive stack depth warning)
- likely others, but those are the 2 that I'm running into.
I don't have the deep TS expertise to know whether this is feasible to implement. It feels like there might be a way to implement this using conditional types for branded types - but as TS is structurally typed, it might not be possible to implement any mapping that would allow matching of a type such as JsonObject. That said, even if this feature were to only support branded types, that would still be valuable and you could wrap any other types in a Brand if you choose to to still fix the case where other types aren't being inferred properly.
Describe the solution you'd like to see
My best attempt at a decent api for this would look something like this:
Step 1: Define a map of server types to client types.
type BrandedType = Tagged<string, 'customString'>;
type TypeOverrides = [
{serverType: BrandedType, clientType: BrandedType}
]
Step 2: Pass the map to a specific trpc.procedure call.
export const publicProcedure = t.procedure<Context, TypeOverrides>;
Describe alternate solutions
While I'm aware that I could solve this by implementing custom transforms - that would introduce unnecessary overhead to map over the entire payload, so I don't see that as a good solution when performance matters (and when does it ever not?)
Otherwise I'm limited to using typescript type assertions, but that kind of defeats the whole purpose of using tRPC.
I'm open to any other suggestions though.
👨👧👦 Contributing
- 🙋♂️ Yes, I'd be down to file a PR implementing this feature!
Activity
ArjunCodess commentedon Sep 19, 2026
hi, i'd like to work on this.
i'd add a type-overrides tuple on procedure so branded types can map 1:1 without a runtime transformer. jsonobject would still need a brand wrapper if ts cannot match it structurally.
should overrides sit on inittrpc.create, or only on procedure?
KATT commentedon Nov 2, 2026
🤖 In v12, the client's output types no longer need an escape hatch for this: a type that's already JSON is kept as written, so recursive types like type-fest's
JsonObjectno longer hit "excessively deep", and branded types likeTagged<string, 'id'>reach the client as the brand. Only values JSON actually changes (aDatebecomesstring, aMapbecomes{}) change type, and a transformer such ascreateSyncTransformer(superjson)keeps those too. https://v12.trpc.io/v12/docs/server/transformers#client-types-follow-the-link. v12 isn't released yet and there's no ETA.