DangerZone
DangerZone5mo ago

Property 'error' does not exist on type 'MiddlewareOKResult<any>'.

Hello, I am building an trpc adapter for nestjs, and I am trying to extend some of trpc's functionality, specifically the procedure middleware by creating a procedure class.
import {
type DataTransformerOptions,
type RootConfig,
type unsetMarker,
} from '@trpc/server';

import type { MiddlewareFunction } from '@trpc/server/src/core/middleware';

type ProcedureParams<Context = any> = {
_config: RootConfig<{
ctx: object & Context;
meta: object;
errorShape: never;
transformer: DataTransformerOptions;
}>;
_ctx_out: object & Context;
_input_in: typeof unsetMarker;
_input_out: typeof unsetMarker;
_output_in: typeof unsetMarker;
_output_out: typeof unsetMarker;
_meta: object;
}

export interface TRPCProcedure<Context = object> {
use: MiddlewareFunction<ProcedureParams<Context>, ProcedureParams<Context>>
}
import {
type DataTransformerOptions,
type RootConfig,
type unsetMarker,
} from '@trpc/server';

import type { MiddlewareFunction } from '@trpc/server/src/core/middleware';

type ProcedureParams<Context = any> = {
_config: RootConfig<{
ctx: object & Context;
meta: object;
errorShape: never;
transformer: DataTransformerOptions;
}>;
_ctx_out: object & Context;
_input_in: typeof unsetMarker;
_input_out: typeof unsetMarker;
_output_in: typeof unsetMarker;
_output_out: typeof unsetMarker;
_meta: object;
}

export interface TRPCProcedure<Context = object> {
use: MiddlewareFunction<ProcedureParams<Context>, ProcedureParams<Context>>
}
I am using the MiddlewareFunction here so it will provide the correct opts implementation. Everything works perfectly, but when I am trying to run it, I am getting a typescript error:
../../node_modules/.pnpm/@trpc+server@10.18.0/node_modules/@trpc/server/src/core/internals/procedureBuilder.ts:387:20 - error TS2339: Property 'error' does not exist on type 'MiddlewareResult<any>'.
Property 'error' does not exist on type 'MiddlewareOKResult<any>'.

387 throw result.error;
~~~~~

../../node_modules/.pnpm/@trpc+server@10.18.0/node_modules/@trpc/server/src/deprecated/internals/procedure.ts:244:20 - error TS2339: Property 'error' does not exist on type 'MiddlewareResult<any>'.
Property 'error' does not exist on type 'MiddlewareOKResult<any>'.

244 throw result.error;
~~~~~

[6:26:38 PM] Found 2 errors. Watching for file changes.
../../node_modules/.pnpm/@trpc+server@10.18.0/node_modules/@trpc/server/src/core/internals/procedureBuilder.ts:387:20 - error TS2339: Property 'error' does not exist on type 'MiddlewareResult<any>'.
Property 'error' does not exist on type 'MiddlewareOKResult<any>'.

387 throw result.error;
~~~~~

../../node_modules/.pnpm/@trpc+server@10.18.0/node_modules/@trpc/server/src/deprecated/internals/procedure.ts:244:20 - error TS2339: Property 'error' does not exist on type 'MiddlewareResult<any>'.
Property 'error' does not exist on type 'MiddlewareOKResult<any>'.

244 throw result.error;
~~~~~

[6:26:38 PM] Found 2 errors. Watching for file changes.
Anyone has an idea of how to solve this? I thought about using the ProcedureBuilder interface but couldn't make it to work.
0 Replies
No replies yetBe the first to reply to this messageJoin