Skip to content

fix(convex): cast request.json() in HTTP actions for TS compatibility#2525

Merged
koala73 merged 1 commit intomainfrom
fix/convex-http-ts-casts
Mar 29, 2026
Merged

fix(convex): cast request.json() in HTTP actions for TS compatibility#2525
koala73 merged 1 commit intomainfrom
fix/convex-http-ts-casts

Conversation

@koala73
Copy link
Copy Markdown
Owner

@koala73 koala73 commented Mar 29, 2026

Summary

Convex's TypeScript environment types request.json() as unknown, stricter than our local tsconfig.json. This caused 4 type errors that blocked convex deploy:

  • convex/http.ts:86 — user-prefs POST body
  • convex/http.ts:156 — telegram-pair-callback update
  • convex/http.ts:201 — relay/deactivate body
  • convex/http.ts:247 — relay/channels body

Fix: await request.json() as typeof body/update on each assignment.

Post-Deploy Monitoring & Validation

No additional operational monitoring required: type-only fix, no runtime behavior change.

Convex's TS environment types request.json() as unknown. Add
'as typeof body/update' casts to fix the 4 type errors that
blocked deployment.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
worldmonitor Ignored Ignored Mar 29, 2026 6:43pm

Request Review

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 29, 2026

Greptile Summary

This PR adds four as typeof body / as typeof update type assertions in convex/http.ts to resolve TypeScript compilation errors introduced by Convex's runtime environment typing request.json() as unknown, which is stricter than what the local tsconfig.json allowed previously.

Changes:

  • convex/http.ts lines 86, 156, 201, 247: await request.json() is now cast to the locally-declared variable type via as typeof body / as typeof update.
  • This is a compile-time-only fix; TypeScript type assertions have zero runtime effect.
  • All four affected handlers already perform proper runtime field validation (type-checks and presence checks) after JSON parsing, so the cast is safe in each case.
  • The fix unblocks convex deploy without altering any observable runtime behaviour.

Confidence Score: 5/5

Safe to merge — purely compile-time fix with no runtime behaviour change.

All four changes are TypeScript-only assertions that carry no runtime cost or risk. Each handler already guards against malformed input through explicit runtime validation after the parse. The as typeof body pattern is idiomatic TypeScript for narrowing unknown JSON results when runtime checks follow immediately.

No files require special attention.

Important Files Changed

Filename Overview
convex/http.ts Four type-only casts added (as typeof body / as typeof update) to satisfy Convex's stricter unknown typing for request.json(); no runtime behavior change, all handlers retain existing runtime validation after the cast.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Router as Convex HTTP Router
    participant Handler as httpAction Handler
    participant Backend as ctx.auth / runMutation / runQuery

    Client->>Router: POST request with JSON body
    Router->>Handler: passes request object
    Handler->>Handler: request.json() as typeof body
    note right of Handler: Type cast (compile-time only)
    alt JSON parse error
        Handler-->>Client: 400 response
    end
    Handler->>Handler: runtime field validation
    alt Fields missing or wrong type
        Handler-->>Client: 400 response
    end
    Handler->>Backend: auth check + mutation/query
    Backend-->>Handler: result
    Handler-->>Client: success response
Loading

Reviews (1): Last reviewed commit: "fix(convex): cast request.json() return ..." | Re-trigger Greptile

@koala73 koala73 merged commit cb9dbca into main Mar 29, 2026
8 checks passed
@koala73 koala73 deleted the fix/convex-http-ts-casts branch March 29, 2026 18:50
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.

1 participant