Skip to content

Commit 35c1dfc

Browse files
committed
fix: resolve TS2742 for tRPC protectedProcedure
Derive procedure type from publicProcedure to avoid non-portable inferred type error in declaration emit.
1 parent c158797 commit 35c1dfc

File tree

18 files changed

+94
-66
lines changed

18 files changed

+94
-66
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
name: "Build"
3535
runs-on: ubuntu-latest
3636
steps:
37-
- uses: actions/checkout@v4
37+
- uses: actions/checkout@v6
3838
# Configure Bun and install dependencies
3939
- uses: oven-sh/setup-bun@v2
4040
with:
@@ -74,7 +74,7 @@ jobs:
7474
- run: docker save api:${{ github.sha }} | gzip > api-image.tar.gz
7575

7676
# Upload build artifacts
77-
- uses: actions/upload-artifact@v4
77+
- uses: actions/upload-artifact@v6
7878
with:
7979
name: "build"
8080
path: "apps/web/dist\napps/app/dist\napps/api/dist\napi-image.tar.gz\n"

apps/api/lib/trpc.ts

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { initTRPC, TRPCError } from "@trpc/server";
1+
import { initTRPC, TRPCError, type TRPCProcedureBuilder } from "@trpc/server";
22
import { flattenError, ZodError } from "zod";
33
import type { TRPCContext } from "./context.js";
44

@@ -18,18 +18,49 @@ const t = initTRPC.context<TRPCContext>().create({
1818
export const router = t.router;
1919
export const publicProcedure = t.procedure;
2020

21-
export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
22-
if (!ctx.session || !ctx.user) {
23-
throw new TRPCError({
24-
code: "UNAUTHORIZED",
25-
message: "Authentication required",
21+
// Derive type from publicProcedure to stay in sync with initTRPC config.
22+
// Explicit annotation required to avoid TS2742 (non-portable inferred type).
23+
type ProtectedProcedure =
24+
typeof publicProcedure extends TRPCProcedureBuilder<
25+
infer TContext,
26+
infer TMeta,
27+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
28+
infer TContextOverrides,
29+
infer TInputIn,
30+
infer TInputOut,
31+
infer TOutputIn,
32+
infer TOutputOut,
33+
infer TCaller
34+
>
35+
? TRPCProcedureBuilder<
36+
TContext,
37+
TMeta,
38+
{
39+
session: NonNullable<TRPCContext["session"]>;
40+
user: NonNullable<TRPCContext["user"]>;
41+
},
42+
TInputIn,
43+
TInputOut,
44+
TOutputIn,
45+
TOutputOut,
46+
TCaller
47+
>
48+
: never;
49+
50+
export const protectedProcedure: ProtectedProcedure = t.procedure.use(
51+
({ ctx, next }) => {
52+
if (!ctx.session || !ctx.user) {
53+
throw new TRPCError({
54+
code: "UNAUTHORIZED",
55+
message: "Authentication required",
56+
});
57+
}
58+
return next({
59+
ctx: {
60+
...ctx,
61+
session: ctx.session,
62+
user: ctx.user,
63+
},
2664
});
27-
}
28-
return next({
29-
ctx: {
30-
...ctx,
31-
session: ctx.session,
32-
user: ctx.user,
33-
},
34-
});
35-
});
65+
},
66+
);

apps/api/lib/utils.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

apps/api/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"composite": true,
55
"declaration": true,
66
"declarationMap": true,
7-
"noEmit": false,
7+
"emitDeclarationOnly": true,
88
"outDir": "./dist",
9+
"tsBuildInfoFile": "../../.cache/tsconfig/api.tsbuildinfo",
910
"types": ["@cloudflare/workers-types", "bun"]
1011
},
1112
"include": ["**/*.ts", "**/*.tsx"],

apps/app/tsconfig.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66
"baseUrl": ".",
77
"paths": {
88
"@/*": ["./*"],
9+
"@repo/api": ["../api"],
10+
"@repo/api/*": ["../api/*"],
11+
"@repo/core": ["../../packages/core"],
12+
"@repo/core/*": ["../../packages/core/*"],
13+
"@repo/db": ["../../db"],
14+
"@repo/db/*": ["../../db/*"],
915
"@repo/ui": ["../../packages/ui"],
10-
"@repo/ui/*": ["../../packages/ui/*"]
16+
"@repo/ui/*": ["../../packages/ui/*"],
17+
"@repo/ws-protocol": ["../../packages/ws-protocol"],
18+
"@repo/ws-protocol/*": ["../../packages/ws-protocol/*"]
1119
}
1220
},
1321
"include": ["**/*.ts", "**/*.tsx", "**/*.json", "./global.d.ts"],

apps/email/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"react": "19.2.3"
2727
},
2828
"devDependencies": {
29-
"react-email": "^5.1.1",
3029
"@react-email/preview-server": "^5.1.1",
3130
"@repo/typescript-config": "workspace:*",
3231
"@types/react": "^19.2.7",
32+
"react-email": "^5.1.1",
3333
"typescript": "~5.9.3"
3434
}
3535
}

apps/web/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
"@repo/ui": "workspace:*",
1818
"astro": "^5.16.6",
1919
"hono": "^4.11.3",
20-
"react": "^19.2.3",
21-
"react-dom": "^19.2.3"
20+
"react-dom": "^19.2.3",
21+
"react": "^19.2.3"
2222
},
2323
"devDependencies": {
24+
"@cloudflare/workers-types": "^4.20251229.0",
2425
"@repo/typescript-config": "workspace:*",
2526
"@tailwindcss/postcss": "^4.1.18",
26-
"@types/react": "^19.2.7",
2727
"@types/react-dom": "^19.2.3",
28+
"@types/react": "^19.2.7",
2829
"autoprefixer": "^10.4.23",
2930
"postcss": "^8.5.6",
3031
"tailwindcss": "^4.1.18",

apps/web/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
},
1717
"include": ["**/*.ts", "**/*.tsx", "**/*.json", "**/*.astro"],
1818
"exclude": ["**/dist/**/*", "**/node_modules/**/*"],
19-
"references": [{ "path": "../api" }, { "path": "../../packages/ui" }]
19+
"references": [{ "path": "../../packages/ui" }]
2020
}

bun.lock

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"devDependencies": {
4040
"@repo/typescript-config": "workspace:*",
4141
"@types/bun": "^1.3.5",
42+
"@types/node": "^25.0.3",
4243
"dotenv": "^17.2.3",
4344
"drizzle-kit": "^0.31.8",
4445
"drizzle-orm": "^0.45.1",

0 commit comments

Comments
 (0)