Skip to content

fix(framework-base): TS2589 deep type instantiation from end-to-end type safety PR #4478

@NathanFlurry

Description

@NathanFlurry

Summary

@rivetkit/framework-base DTS build fails with TS2589: Type instantiation is excessively deep and possibly infinite after PR #4360 ("end-to-end type safety for queue and event APIs") made Client<Registry> and related types significantly more complex.

Root Cause

PR #4360 added deeper generic type chains for queue and event APIs. When framework-base calls generic functions like getOrCreateActor() and create() that use Client<Registry>, TypeScript's type instantiation now exceeds its recursion limit.

The framework-base source itself also changed (144 lines) in the same timeframe, compounding the issue.

Current Workaround

In the 2.1.6-rc.1 release, we applied as any casts to the getOrCreateActor and create function calls in framework-base/src/mod.ts, with an explicit return type annotation on the public getOrCreateActor API to prevent the any from leaking to consumers (like @rivetkit/react).

// Before (causes TS2589)
) => getOrCreateActor(client, createOpts, store, cache, actorOpts),

// After (workaround)
): { mount: () => () => void; state: ActorsStateDerived<Registry, ActorName>; key: string; } =>
  (getOrCreateActor as any)(client, createOpts, store, cache, actorOpts),

Direct calls to create<Registry, ActorName>(...) were also cast to (create as Function)(...).

Proper Fix

The as any casts suppress type checking at these call sites. A proper fix should either:

  1. Simplify the Client<Registry> type chain to stay within TS recursion limits
  2. Restructure the generic parameters in getOrCreateActor and create to avoid deep instantiation
  3. Use intermediate type aliases to break the recursion chain

Affected Files

  • rivetkit-typescript/packages/framework-base/src/mod.ts (lines 175, 297, 335, 375)

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