punn
punn2y ago

Circular Reference Error

Getting this error at build time
Type error: Type of property '"actions/openai:sandboxChat"' circularly references itself in mapped type 'NameModule<"actions/openai", typeof import("/Users/punnkam/Desktop/projects/hostai/convex/actions/openai")>
Type error: Type of property '"actions/openai:sandboxChat"' circularly references itself in mapped type 'NameModule<"actions/openai", typeof import("/Users/punnkam/Desktop/projects/hostai/convex/actions/openai")>
17 Replies
punn
punnOP2y ago
I'm returning an object within an action, wondering if that is the issue
ballingt
ballingt2y ago
depends on your code some but you may need to add a type annotation or cast
punn
punnOP2y ago
Should I be casting server side?
punn
punnOP2y ago
The error points to client side code and not even the action I'm using
No description
ballingt
ballingt2y ago
That's would probably work, casting the return value of the action sandboxChat Yeah, server-side
punn
punnOP2y ago
casting as any doesn't seem to work
ballingt
ballingt2y ago
where are you casting to any? want to screenshare for a few minutes?
punn
punnOP2y ago
async ({ runQuery }, chats, listingId): Promise<any> and return { intent: intentResponseObj, response: resBody } as any; i need to get going but i'll be back on tomorrow. only affecting the production build so not super urgent
ballingt
ballingt2y ago
casting the whole action inside the wrapper may help
punn
punnOP2y ago
do you mind giving me an example?
ballingt
ballingt2y ago
const sandboxChat = action(({runAction}, chats, listingId) => { ... } as any);
const sandboxChat = action(({runAction}, chats, listingId) => { ... } as any);
or instead of any, as the right type This is tradeoff we're making for better completion and less codegen at this point, but it's pretty annoying when it happens.
punn
punnOP2y ago
This throws this error
No description
punn
punnOP2y ago
this is the function for reference https://codepaste.xyz/posts/qShHONDXUGuLg10uW087
ballingt
ballingt2y ago
I haven't been able to reproduce your error yet, but the syntax I meant for the any cast looks like this
import { action } from "../_generated/server";

export const sandboxChat = action((async (
{ runQuery }: any,
chats: any,
listingId: any
): Promise<any> => {
const apiKey = process.env.OPENAI_API_KEY;
const intentResponseObj = { a: "asdf", b: "asdfasdf" };
const messages = await runQuery("listMessages");
return { intent: 1, response: 2 };
}) as any);
import { action } from "../_generated/server";

export const sandboxChat = action((async (
{ runQuery }: any,
chats: any,
listingId: any
): Promise<any> => {
const apiKey = process.env.OPENAI_API_KEY;
const intentResponseObj = { a: "asdf", b: "asdfasdf" };
const messages = await runQuery("listMessages");
return { intent: 1, response: 2 };
}) as any);
What's the version of TypeScript you're using here? I'd love to get a repro of this, I think this file is interacting with others there are a few more steps you could take here, one is using actionGeneric instead of action like
import { actionGeneric as action } from "convex/server";
export const sandboxChat = action((async (
...
import { actionGeneric as action } from "convex/server";
export const sandboxChat = action((async (
...
RJ
RJ2y ago
I think that any time I've encountered this it's been sufficient to annotate the return type of the function passed to action (or query or mutation). Your attempt might not be working because you're annotating as Promise<any> rather than something more specific (e.g. Promise<string>). Could be worth trying the latter and seeing if that helps. Even Promise<{ intent: any; response: any }> might be better!
punn
punnOP2y ago
gotcha thank you will give those a shot this fix worked thank you!
RJ
RJ2y ago
Woohoo, no problem!

Did you find this page helpful?