Skip to content

[FE-08] Replace all any types in API layer with strict interfaces and Zod runtime validation #276

Description

@Leothosine

Problem

frontend/lib/api/admin.ts uses the any type for updateProfile (line 149), getAnalytics (line 201), and several mutation return values. useQuery and useMutation calls throughout the codebase lack generic type parameters. If the backend changes a response shape, TypeScript gives no compile-time warning - runtime errors surface deep inside component render logic.

Proposed Solution

  1. Create frontend/lib/types/api.ts with strict response interfaces for every endpoint: DashboardStatsResponse, MenuItemResponse, AdminUserResponse, GalleryImageResponse, ContactSubmissionResponse, AnalyticsResponse
  2. Create a discriminated union for API errors: type ApiError = { statusCode: number; message: string; details?: Record<string, string[]> }
  3. Add Zod schemas for the 5 most critical responses and validate them in the API client
  4. Apply React Query generics: useQuery<MenuItemResponse[], ApiError>()
  5. Enable noImplicitAny in tsconfig.json

Acceptance Criteria

  • Zero uses of any type in frontend/lib/api/
  • TypeScript compile error if a component accesses a field not in the response interface
  • A mismatched backend response throws a ZodError with the field name before reaching component state
  • noImplicitAny: true in tsconfig.json
  • All useQuery / useMutation calls have explicit generic type parameters

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions