How does trpc typing work
I'm curious to know how trpc generates type without a code gen step , i am trying to acheive something like this
3 Replies
My approach might be wrong, i'm trying to build something similar . Any help is appreciated
Later on whenever i try to invoke a method similar to mutate , i need the typing of the input to be in available in the parameter of the mutate method .
You need the class itself to have a generic arg
And you probably want to use method chaining like trpc does, which means instead of setting a property on a class, you have a method which returns a new class instance containing the functions that can be called from that point (I prefer implementing that without classes at all and just returning objects with functions inside them)
Something like this:
The benefit of having a nested structure like that is the inner functions have easy access to all the generic types and variables/args from the outer functions
will give that a try .