TypeScript Circular Reference Issue with Convex Internal Functions
hi guys i have a weird issue i provided the code in the img
The Problem š
When calling internal functions from public functions in the same Convex project, TypeScript creates a circular type dependency:
Error:
error TS7022: 'getProfile' implicitly has type 'any' because it does not
have a type annotation and is referenced directly or indirectly in its own initializer.
Why It Happens š¤
TypeScript tries to infer the return type of getProfile
To infer it, it needs to compile internal.agents.profiles.getProfile
But that's in the _generated/api which is generated FROM compiling this file
Chicken and egg problem ā Circular dependency!
The Solution is in the img.
Why This Works ⨠returns: validator ā Runtime validation + type inference : Promise<any> on handler ā Breaks the circular TypeScript compilation According to Convex Docs š Public functions: Validators recommended for security Internal functions: Validators are optional (but we use them for stricter type safety) Handler type annotations: Not mentioned in docs (because it's a TS edge case) TL;DR When calling internal functions from public functions in the same project: ā Add returns: validators to ALL functions ā Add : Promise<any> to handlers that call ctx.runQuery/runMutation on internal functions
Why This Works ⨠returns: validator ā Runtime validation + type inference : Promise<any> on handler ā Breaks the circular TypeScript compilation According to Convex Docs š Public functions: Validators recommended for security Internal functions: Validators are optional (but we use them for stricter type safety) Handler type annotations: Not mentioned in docs (because it's a TS edge case) TL;DR When calling internal functions from public functions in the same project: ā Add returns: validators to ALL functions ā Add : Promise<any> to handlers that call ctx.runQuery/runMutation on internal functions


0 Replies