Skip to content

fix(protect): type-safe scaffolded guard.ts (strict TanStack build)#75

Merged
ejntaylor merged 1 commit into
mainfrom
fix/protect-template-types
Jul 14, 2026
Merged

fix(protect): type-safe scaffolded guard.ts (strict TanStack build)#75
ejntaylor merged 1 commit into
mainfrom
fix/protect-template-types

Conversation

@patchstackdave

Copy link
Copy Markdown
Contributor

A real patchstack-connect protect install failed the target app's tsc build with two errors in the scaffolded guard.ts:

guard.ts: TS2345 … Type 'string' is not assignable to type '"block" | "dry-run" | undefined'.
start.ts: TS2322 … Type 'Promise<unknown>' is not assignable to type 'Promise<RequestServerResult | Response>'.

Cause & fix

  • mode was inferred as string in the published template → the createProtection(...) argument was rejected. Pin it: const mode: "block" | "dry-run" = ….
  • screenResponse(response: unknown): Promise<unknown> (added in feat(protect): scaffold response screening + first scaffolder tests #70) made the request-middleware server fn return Promise<unknown>, which TanStack's RequestMiddlewareServerFnResult rejects. Make it a generic passthrough screenResponse<T>(response: T): Promise<T>, so screenResponse(await next()) preserves next()'s return type. (Only guard.ts changes — the start.ts error is caused by this signature, so it clears with no start.ts edit.)

Both were reproduced under tsc --strict in isolation and confirmed fixed. Added a scaffolder regression test asserting the guard ships these type-safe signatures.

Note

connect's own typecheck doesn't compile the .ts templates against a real TanStack app, which is why this slipped through #70. The new assertion is a content guard; a full template-typecheck-against-TanStack pass is a possible follow-up.

🤖 Generated with Claude Code

A `patchstack-connect protect` install failed `tsc` in the target app with two
errors in the scaffolded guard:

- `mode` inferred as `string`, not `"block" | "dry-run"` → createProtection arg
  rejected. Pin the annotation: `const mode: "block" | "dry-run" = …`.
- `screenResponse(response: unknown): Promise<unknown>` made the request
  middleware's server fn return `Promise<unknown>`, which TanStack's
  RequestMiddlewareServerFnResult rejects. Make it a generic passthrough
  `screenResponse<T>(response: T): Promise<T>` so `screenResponse(await next())`
  preserves next()'s return type.

Both reproduced + fixed under `tsc --strict` in isolation. Added a scaffolder
regression test asserting the guard ships these type-safe signatures.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderbuds

coderbuds Bot commented Jul 14, 2026

Copy link
Copy Markdown

Introduces explicit union types and generics for strict type safety in guard.ts.

🎯 Quality: 100% Elite · 📦 Size: Small

📈 This month: Your 28th PR — above team average · Averaging Excellent

See how your team is trending →

@patchstackdave

Copy link
Copy Markdown
Contributor Author

/review

@ejntaylor ejntaylor merged commit dd833ed into main Jul 14, 2026
4 checks passed
@ejntaylor ejntaylor deleted the fix/protect-template-types branch July 14, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants