question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: Split `GetInferenceHelpers` in `Output` and `Input`

See original GitHub issue

Describe the feature you’d like to request

Instead of having inference helpers that expose input and output together, I think we should make two distinct inference helpers

Current:

type RouterTypes = GetInferenceHelpers<AppRouter>;

type Post = RouterTypes['public']['post']['list']['output']['items'][number];
// Getting `items[number]` of `public.post.list.output`
// Hard to read

Describe the solution you’d like to see

Better legibility:

type RouterOutput = GetOutputInferenceHelpers<AppRouter>;
type RouterInput = GetInputInferenceHelpers<AppRouter>;


type Post = RouterOutput['public']['post']['list']['items'][number];

Split inference helpers in two.

Desribe alternate solutions

We could also allow for this, which is even better legibility but will negatively affect TS perf on bigger routers.

Flattened path

type RouterOutput = inferRouterOutput<AppRouter>;
type RouterInput = inferRouterInput<AppRouter>;


type Post = RouterOutput['public.post.list']['items'][number];

Fake representation of a router

@sachinraja brought up this idea as well:

// could be a proxy for a readable error or we could just straight-up lie about the types

const routerOutputs = createRouterOutputTypes<AppRouter>();
const routerInputs = createRouterOutputTypes<AppRouter>();

type Post = typeof routerOutputs.post.byId

It’s arguably a lot nicer for power users, but we do lie about the types.

Additional information

Discussion about naming: https://github.com/trpc/trpc/discussions/2825

👨‍👧‍👦 Contributing

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sachinrajacommented, Oct 23, 2022

I would go with option 4:

  • Keep the GetXInferenceHelpers and inferProcedureX
  • Remove GetInferenceHelpers
  • Change the docs so we show a clear preference for GetXInferenceHelpers
1reaction
rhenriquez28commented, Oct 23, 2022

It wouldn’t because TS defers evaluation of object properties.

Oh well, TIL. That being said, between just splitting the inference helpers and using the flattened path (with whichever approach you decide to go with), I very much prefer the flattened path. It’s more readable and faster to work with.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Splitting - IBM
You can use OUTFIL's SPLIT parameter to put the first record into OUTPUT1, ... With 17 input records, the results produced for OUTPUT1...
Read more >
Output / Input - Facebook
Congrats to Output / Input as their cover of The Isley Bro's "Here We Go Again" features on. Expansion Records's Luxury Soul 2023...
Read more >
How Computers Work: Input and Output
Input and output may sometimes be separated by time or distance or both. Here are some examples: Factory workers input data by punching...
Read more >
Input and output | Think Java | Trinket
This chapter will show you how to read input from the keyboard, use that input to calculate a result, and then format that...
Read more >
ESG-inputs vs ESG-outputs and what really matters - LinkedIn
The conclusion of the FT article seems to be that we should split the ESG concept into ESG-input and ESG-output in order to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found