diff --git a/packages/server/src/router-utils.ts b/packages/server/src/router-utils.ts index c31e55ddc..3ed6498bb 100644 --- a/packages/server/src/router-utils.ts +++ b/packages/server/src/router-utils.ts @@ -356,7 +356,11 @@ export async function walkProcedureContractsAsync( export type UnlaziedRouter = T extends AnyProcedure ? T : { - [K in keyof T]: T[K] extends Lazyable ? UnlaziedRouter : never + [K in keyof T]: T[K] extends AnyRouter + ? UnlaziedRouter + : T[K] extends Lazyable + ? UnlaziedRouter + : never } /** diff --git a/packages/server/src/router.ts b/packages/server/src/router.ts index 521b4265b..7d63b4bf5 100644 --- a/packages/server/src/router.ts +++ b/packages/server/src/router.ts @@ -9,7 +9,7 @@ import type { import type { Context, MergedContext } from './context' import type { Lazyable } from './lazy' -import type { Procedure } from './procedure' +import type { Procedure, ProcedureDefinition } from './procedure' export type Router = | Procedure @@ -38,14 +38,17 @@ export type InferRouterInitialContext = T extends Router = - T extends Procedure - ? UInitialContext - : { - [K in keyof T]: T[K] extends Lazyable +export type InferRouterInitialContexts = T extends { + '~orpc': ProcedureDefinition +} + ? UInitialContext + : { + [K in keyof T]: T[K] extends AnyRouter + ? InferRouterInitialContexts + : T[K] extends Lazyable ? InferRouterInitialContexts : never - } + } /** * Infer all current context of the router. @@ -55,14 +58,17 @@ export type InferRouterInitialContexts = * * @see {@link https://orpc.dev/docs/router#infer-router-final-contexts | Router - Infer Router Final Contexts} */ -export type InferRouterFinalContexts = - T extends Procedure - ? MergedContext - : { - [K in keyof T]: T[K] extends Lazyable +export type InferRouterFinalContexts = T extends { + '~orpc': ProcedureDefinition +} + ? MergedContext + : { + [K in keyof T]: T[K] extends AnyRouter + ? InferRouterFinalContexts + : T[K] extends Lazyable ? InferRouterFinalContexts : never - } + } /** * Infer all router inputs. @@ -72,14 +78,17 @@ export type InferRouterFinalContexts = * * @see {@link https://orpc.dev/docs/router#infer-router-inputs | Router - Infer Router Inputs} */ -export type InferRouterInputs = - T extends Procedure - ? InferSchemaInput - : { - [K in keyof T]: T[K] extends Lazyable +export type InferRouterInputs = T extends { + '~orpc': ProcedureDefinition +} + ? InferSchemaInput + : { + [K in keyof T]: T[K] extends AnyRouter + ? InferRouterInputs + : T[K] extends Lazyable ? InferRouterInputs : never - } + } /** * Infer all router outputs. @@ -89,39 +98,48 @@ export type InferRouterInputs = * * @see {@link https://orpc.dev/docs/router#infer-router-outputs | Router - Infer Router Outputs} */ -export type InferRouterOutputs = - T extends Procedure - ? InferSchemaOutput - : { - [K in keyof T]: T[K] extends Lazyable +export type InferRouterOutputs = T extends { + '~orpc': ProcedureDefinition +} + ? InferSchemaOutput + : { + [K in keyof T]: T[K] extends AnyRouter + ? InferRouterOutputs + : T[K] extends Lazyable ? InferRouterOutputs : never - } + } /** * Infer the union of throwable errors for entire router. * * @see {@link https://orpc.dev/docs/router#infer-router-error | Router - Infer Router Error} */ -export type InferRouterError = - T extends Procedure - ? ORPCErrorFromErrorMap | ThrowableError - : { - [K in keyof T]: T[K] extends Lazyable +export type InferRouterError = T extends { + '~orpc': ProcedureDefinition +} + ? ORPCErrorFromErrorMap | ThrowableError + : { + [K in keyof T]: T[K] extends AnyRouter + ? InferRouterError + : T[K] extends Lazyable ? InferRouterError : never - }[keyof T] + }[keyof T] /** * Infer throwable errors for each procedure, preserving the router shape. * * @see {@link https://orpc.dev/docs/router#infer-router-errors | Router - Infer Router Errors} */ -export type InferRouterErrors = - T extends Procedure - ? ORPCErrorFromErrorMap | ThrowableError - : { - [K in keyof T]: T[K] extends Lazyable +export type InferRouterErrors = T extends { + '~orpc': ProcedureDefinition +} + ? ORPCErrorFromErrorMap | ThrowableError + : { + [K in keyof T]: T[K] extends AnyRouter + ? InferRouterErrors + : T[K] extends Lazyable ? InferRouterErrors : never - } + }