Skip to content

feat: simplify output types of Router and Procedure #4709

Closed

Description

@KATT

Describe the feature you'd like to request

Simplify routers and procedure types in order to:

  • reduce .d.ts-footprint (Context is duplicated everywhere)
  • improve TS perf
  • allow design to be more happy for defining standalone procedures without a router
  • nicer procedures when hovering / autocompletion

Describe the solution you'd like to see

  • built procedures should just be a simple structure containing _input_in, _output_out
  • instead of passing TRouter extends AnyRouter around everywhere, we should pass around TConfig
  • (procedures are not aware of the TConfig once "built")
  • when we create client helpers, we still need TConfig, so when we first initialize TRPCClient we first extract TConfig and pass through the decorator

Describe alternate solutions

not doing it

Additional information

Currently a built router looks something like this:

export declare const router0: import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
    ctx: {};
    meta: object;
    errorShape: import("@trpc/server").DefaultErrorShape;
    transformer: import("@trpc/server").DefaultDataTransformer;
}>, {
    greeting: import("@trpc/server").BuildProcedure<"query", {
        _config: import("@trpc/server").RootConfig<{
            ctx: {};
            meta: object;
            errorShape: import("@trpc/server").DefaultErrorShape;
            transformer: import("@trpc/server").DefaultDataTransformer;
        }>;
        _meta: object;
        _ctx_out: {};
        _input_in: {
            who: string;
        };
        _input_out: {
            who: string;
        };
        _output_in: typeof import("@trpc/server").unsetMarker;
        _output_out: typeof import("@trpc/server").unsetMarker;
    }, string>;
}>;

Where after this, it'd look something like

export declare const router0: import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
    ctx: {};
    meta: object;
    errorShape: import("@trpc/server").DefaultErrorShape;
    transformer: import("@trpc/server").DefaultDataTransformer;
}>, {
    greeting: import("@trpc/server").Procedure<"query", {
        _input_in: {
            who: string;
        };
        _output_out: undefined;
    }, string>;
}>;

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR implementing this feature!

T-119

Activity

  1. changed the title [-]feat: simplify types of `Router` and `Procedure`[/-] [+][T-119] feat: simplify types of `Router` and `Procedure`[/+] on Aug 11, 2023
  2. changed the title [-][T-119] feat: simplify types of `Router` and `Procedure`[/-] [+]feat: simplify types of `Router` and `Procedure`[/+] on Aug 11, 2023
  3. changed the title [-]feat: simplify types of `Router` and `Procedure`[/-] [+]feat: simplify output types of `Router` and `Procedure`[/+] on Aug 11, 2023
  4. added
    ⏭ major bump needed
    on Aug 24, 2023
  5. locked as resolved and limited conversation to collaborators on Oct 10, 2023
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

    ⏭ major bump needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions