Skip to content

armgit / crm

Public Imported from GitHub
0

Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.

TypeScript

Do not rely on discriminant narrowing in the tRPC error middleware

Lewis Carhart03c602f5de5d
diff --git a/apps/api/src/trpc/middlewares/domain-error.middleware.ts b/apps/api/src/trpc/middlewares/domain-error.middleware.ts
index 95e0d134..12b37f73 100644
--- a/apps/api/src/trpc/middlewares/domain-error.middleware.ts
+++ b/apps/api/src/trpc/middlewares/domain-error.middleware.ts
@@ -48,7 +48,12 @@ export class DomainErrorMiddleware implements TRPCMiddleware {
return result;
}
- const cause = (result.error as { cause?: unknown } | undefined)?.cause;
+ // Read `error` off a widened alias rather than the narrowed union. The
+ // `ok` discriminant narrows under this repo's tsconfig but not under the
+ // one Vercel's Node builder compiles with, where `result.error` is a
+ // deploy-breaking TS2339. The guard above already proved `ok` is false.
+ const failure = result as { error?: unknown };
+ const cause = (failure.error as { cause?: unknown } | undefined)?.cause;
if (cause instanceof HttpException) {
throw new TRPCError({