TS2589 "Type instantiation is excessively deep" - Workaround & Looking for Better Solutions
Getting
TS2589: Type instantiation is excessively deep and possibly infinite in a ~300 module Convex project when using ctx.runQuery/runMutation with internal.* references.Disclaimer: I'm relatively new to TypeScript/Convex, so if there's an obvious solution I'm missing, please let me know!
Working Workaround:
Replace ES imports with
require():Stats:
- Applied to 27 files so far
- TypeScript 5.9.3, Convex 1.x
- Zero runtime impact
- Hits "hot path" functions called from many places (session validation, webhooks, AI tools)
My Concerns:
- Loses type safety at import boundary
- Feels like a workaround, not a fix
- The
as any conflicts with strict TypeScript philosophyQuestions:
1. Has anyone else hit this at scale?
2. Is there a better workaround (tsconfig option, different pattern)?
3. Should I refactor to reduce
ctx.runQuery(internal.*) calls?4. Is this a known scaling limitation?
5. Convex team: Any guidance on type generation for larger projects?
Context:
Pre-launch SaaS hitting this around 300 modules with heavy cross-function calls for shared infrastructure (session validation, conversation state, webhook processing, RAG operations).
Thanks for any insights!
