Skip to content

TS2589: component types too deep — breaks host app typecheck #38

@bntvllnt

Description

@bntvllnt

Problem

Registering @vllnt/convex-api-keys as a Convex component adds deeply nested types to the host app's generated api.d.ts. This pushes TypeScript past its recursion limit (TS2589) in files that:

  • Use action() / query() / mutation() from _generated/server
  • Use v.union() with 6+ literals
  • Use createTracedFunctions() or any wrapper that resolves through the full DataModel

Reproduction

// convex.config.ts
import apiKeys from "@vllnt/convex-api-keys/convex.config";
app.use(apiKeys);

// any file using action() from _generated/server
export const myAction = action({ // TS2589: Type instantiation is excessively deep
  args: { type: v.union(v.literal("a"), v.literal("b"), v.literal("c")) },
  ...
});

Workarounds currently needed

  • actionGeneric from convex/server instead of action from _generated/server
  • *Generic builders (queryGeneric, internalQueryGeneric, etc.) in traced function wrappers
  • const internal: any = _internal to break the type chain on ctx.runQuery(internal....) calls
  • --max-old-space-size=8192 for web typecheck (OOM from transitive type resolution)

Expected

Registering the component should not increase type depth enough to trigger TS2589 in the host app. Other @convex-dev/* components (workflow, rate-limiter, presence, workpool, crons) don't cause this.

Likely cause

The component's schema or generated types export deeply nested generic types. The sub-components (@convex-dev/aggregate, @convex-dev/sharded-counter, @convex-dev/rate-limiter, @convex-dev/crons) each add type depth, and stacking 4 of them compounds the nesting.

Environment

  • @vllnt/convex-api-keys: 0.1.1-canary.f11443e
  • convex: 1.31.2
  • TypeScript: 5.9.3

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