Skip to content

fix(api): add Fastify request type augmentation to eliminate as any casts#6

Open
Gmymymy wants to merge 1 commit into
zai-org:mainfrom
Gmymymy:fix/api-fastify-request-type-augmentation
Open

fix(api): add Fastify request type augmentation to eliminate as any casts#6
Gmymymy wants to merge 1 commit into
zai-org:mainfrom
Gmymymy:fix/api-fastify-request-type-augmentation

Conversation

@Gmymymy
Copy link
Copy Markdown

@Gmymymy Gmymymy commented May 20, 2026

Summary

  • Add packages/api/src/types/fastify.d.ts to extend FastifyRequest with typed user, authSession, and workspaceMember properties
  • Remove all (request as any).user, (request as any).authSession, and (request as any).workspaceMember casts across 20 files
  • Replace (request.params as any).workspaceId with the narrower (request.params as { workspaceId?: string }) cast in middleware

Motivation

The three properties are attached to FastifyRequest at runtime by the auth and workspace middleware, but TypeScript had no knowledge of them — requiring as any casts on every read. This PR registers the types once via Fastify's module-augmentation API so all access sites become typed.

Test Plan

  • No runtime behaviour changes — purely a type-level fix
  • TypeScript compiler should accept all 20 modified files without errors
  • Existing tests should pass unchanged

… casts

Add `packages/api/src/types/fastify.d.ts` to extend the Fastify
`FastifyRequest` interface with `user`, `authSession`, and
`workspaceMember` properties that middleware attaches at runtime.

This replaces all `(request as any).user`, `(request as any).authSession`,
and `(request as any).workspaceMember` casts across 20 files with direct
typed property access, giving TypeScript visibility into these fields for
autocompletion, rename refactors, and compile-time safety.

No runtime behaviour changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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