Skip to content

TypeScript 5.4 build error: eventsQuerySchema.omit() loses types after upgrade #3059

@WEugen

Description

@WEugen

Environment

  • Next.js: 15.5.4
  • TypeScript: 5.4.4 (via pnpm.overrides)
  • Dub version: Latest (fresh clone from main)
  • OS: Debian 12

Problem

Build fails with TypeScript errors after upgrading from TS 5.2.2 to 5.4.4.

Error in apps/web/app/(ee)/api/events/export/route.ts:

Type error: Property 'domain' does not exist on type '{ page: number; event: "clicks" | "sales" | "leads"; sortBy: "timestamp"; limit: number; ... }'.

Error in apps/web/app/(partner)/api/partner-profile/programs/[programId]/events/route.ts:

Type error: Property 'linkId' does not exist on type '{}'.

Root Cause

eventsQuerySchema uses .omit() which loses all inherited types in TS 5.4+:

export const eventsQuerySchema = analyticsQuerySchema
  .omit({ groupBy: true, sortBy: true })
  .extend({
    event: z.enum(EVENT_TYPES).default("clicks"),
    // ... other fields
  });

After .omit(), TypeScript no longer infers fields from analyticsQuerySchema.

Question

Is this a known issue? Should I add explicit .extend() for all required fields, or is there a better approach for TS 5.4 compatibility?

Workaround

Adding explicit fields in .extend() fixes the issue, but seems verbose. Is this expected?

After .omit(), TypeScript no longer infers fields from analyticsQuerySchema.

Question
Is this a known issue? Should I add explicit .extend() for all required fields, or is there a better approach for TS 5.4 compatibility?
Workaround
Adding explicit fields in .extend() fixes the issue, but seems verbose. Is this expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions