Memefella
Memefella3mo ago

Router output types not mapping?

I can get it manually, but can't get it with inferRouterOutputs, returns unknown. Any ideas? Attached screenshots showing the issue
No description
No description
2 Replies
Memefella
MemefellaOP3mo ago
works with this, super weird
import { AnyProcedure, inferProcedureOutput, AnyRouter, AnyTRPCClientTypes, TRPCRouterRecord } from '@trpc/server';
import type { inferObservableValue } from '@trpc/server/observable';

export type GetInferenceHelpers<
TType extends 'input' | 'output',
TRoot extends AnyTRPCClientTypes,
TRecord extends TRPCRouterRecord
> = {
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
? $Value extends TRPCRouterRecord
? GetInferenceHelpers<TType, TRoot, $Value>
: $Value extends AnyProcedure
? inferProcedureOutput<$Value> // inferTransformedProcedureOutput<TRoot, $Value>
: never
: never;
};

export type inferRouterOutputs<TRouter extends AnyRouter> = GetInferenceHelpers<
'output',
TRouter['_def']['_config']['$types'],
TRouter['_def']['record']
>;

export type RouterOutput = inferRouterOutputs<Router>;

type SpecificOutput = Router['_def']['record']['createInterfaceDraft']['_def']['$types']['output'];
type TestOutput = RouterOutput['createInterfaceDraft'];
import { AnyProcedure, inferProcedureOutput, AnyRouter, AnyTRPCClientTypes, TRPCRouterRecord } from '@trpc/server';
import type { inferObservableValue } from '@trpc/server/observable';

export type GetInferenceHelpers<
TType extends 'input' | 'output',
TRoot extends AnyTRPCClientTypes,
TRecord extends TRPCRouterRecord
> = {
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
? $Value extends TRPCRouterRecord
? GetInferenceHelpers<TType, TRoot, $Value>
: $Value extends AnyProcedure
? inferProcedureOutput<$Value> // inferTransformedProcedureOutput<TRoot, $Value>
: never
: never;
};

export type inferRouterOutputs<TRouter extends AnyRouter> = GetInferenceHelpers<
'output',
TRouter['_def']['_config']['$types'],
TRouter['_def']['record']
>;

export type RouterOutput = inferRouterOutputs<Router>;

type SpecificOutput = Router['_def']['record']['createInterfaceDraft']['_def']['$types']['output'];
type TestOutput = RouterOutput['createInterfaceDraft'];
No description
Memefella
MemefellaOP3mo ago
anybody know how to get trpc/react working with the above?