johste
johste16mo ago

Need help identifying the generic client side type of procedures

Hi! I think my question is better explained by what I'm trying to achive than anything else: I like to create a function called "subscribe" that can receive any subscription procedure and subscribe to it: e.g (sudo code):
const onRandomNumberRecived = (n: number) => {}
subscribe(trpc.randomNumber, onRandomNumberRecived);
const onRandomNumberRecived = (n: number) => {}
subscribe(trpc.randomNumber, onRandomNumberRecived);
Below is the infered type, but I'm pretty sure there is an generic type to represent such a thing "somewhere":
(property) randomNumber: {
subscribe: SubscriptionResolver<BuildProcedure<"subscription", {
_config: RootConfig<{
ctx: {};
meta: object;
errorShape: DefaultErrorShape;
transformer: DefaultDataTransformer;
}>;
_ctx_out: {};
_input_in: typeof unsetMarker;
_input_out: typeof unsetMarker;
_output_in: typeof unsetMarker;
_output_out: typeof unsetMarker;
_meta: object;
}, Observable<{randomNumber: number;}, unknown>>>;
(property) randomNumber: {
subscribe: SubscriptionResolver<BuildProcedure<"subscription", {
_config: RootConfig<{
ctx: {};
meta: object;
errorShape: DefaultErrorShape;
transformer: DefaultDataTransformer;
}>;
_ctx_out: {};
_input_in: typeof unsetMarker;
_input_out: typeof unsetMarker;
_output_in: typeof unsetMarker;
_output_out: typeof unsetMarker;
_meta: object;
}, Observable<{randomNumber: number;}, unknown>>>;
I've been digging through the source code, but so far I had no luck reproducing it. Have anyone attempted something similar?
1 Reply
Kseikyo
Kseikyo16mo ago
I'm not sure what you're trying to do, but if you're trying to get the type for subscribe, you can use the inferRouterInputs
/**
* Inference helper for inputs.
*
* @example type HelloInput = RouterInputs['example']['hello']
*/
export type RouterInputs = inferRouterInputs<AppRouter>;

/**
* Inference helper for outputs.
*
* @example type HelloOutput = RouterOutputs['example']['hello']
*/
export type RouterOutputs = inferRouterOutputs<AppRouter>;
/**
* Inference helper for inputs.
*
* @example type HelloInput = RouterInputs['example']['hello']
*/
export type RouterInputs = inferRouterInputs<AppRouter>;

/**
* Inference helper for outputs.
*
* @example type HelloOutput = RouterOutputs['example']['hello']
*/
export type RouterOutputs = inferRouterOutputs<AppRouter>;