Skip to content

feat: Support defining type maps as an escape hatch #6800

Open

Description

@alex-e-leon

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.

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

  1. ArjunCodess commented on Sep 19, 2026

    @ArjunCodess

    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?

  2. KATT commented on Nov 2, 2026

    @KATT
    Member

    🤖 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 JsonObject no longer hit "excessively deep", and branded types like Tagged<string, 'id'> reach the client as the brand. Only values JSON actually changes (a Date becomes string, a Map becomes {}) change type, and a transformer such as createSyncTransformer(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.

  3. added
    next-major/definite
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    next-major/definite

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions