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:
- Simplify the
Client<Registry> type chain to stay within TS recursion limits
- Restructure the generic parameters in
getOrCreateActor and create to avoid deep instantiation
- Use intermediate type aliases to break the recursion chain
Affected Files
rivetkit-typescript/packages/framework-base/src/mod.ts (lines 175, 297, 335, 375)
Summary
@rivetkit/framework-baseDTS build fails withTS2589: Type instantiation is excessively deep and possibly infiniteafter PR #4360 ("end-to-end type safety for queue and event APIs") madeClient<Registry>and related types significantly more complex.Root Cause
PR #4360 added deeper generic type chains for queue and event APIs. When
framework-basecalls generic functions likegetOrCreateActor()andcreate()that useClient<Registry>, TypeScript's type instantiation now exceeds its recursion limit.The
framework-basesource 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 anycasts to thegetOrCreateActorandcreatefunction calls inframework-base/src/mod.ts, with an explicit return type annotation on the publicgetOrCreateActorAPI to prevent theanyfrom leaking to consumers (like@rivetkit/react).Direct calls to
create<Registry, ActorName>(...)were also cast to(create as Function)(...).Proper Fix
The
as anycasts suppress type checking at these call sites. A proper fix should either:Client<Registry>type chain to stay within TS recursion limitsgetOrCreateActorandcreateto avoid deep instantiationAffected Files
rivetkit-typescript/packages/framework-base/src/mod.ts(lines 175, 297, 335, 375)