#6800·trpc

feat: Support defining type maps as an escape hatch

Author: alex-e-leonCreated Jun 2, 2025Updated Sep 19, 2026

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:

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.

bash
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!