gwilliamnn
gwilliamnn3mo ago

Type error using ActoinCache

mport { ActionCache } from "@convex-dev/action-cache";
import { components, internal } from "./_generated/api";
import { action } from "./_generated/server";

export const getAgjdbArqatendCached = new ActionCache(components.actionCache, {
name: "getAgjdbArqatend",
action: internal.actions.internal.getAgjdbArqatendInternal
})

export const getAgjdbArqatendCachedAction = action({
handler: async (ctx): Promise<string> => {
return await getAgjdbArqatendCached.fetch(ctx, {});
}
})
mport { ActionCache } from "@convex-dev/action-cache";
import { components, internal } from "./_generated/api";
import { action } from "./_generated/server";

export const getAgjdbArqatendCached = new ActionCache(components.actionCache, {
name: "getAgjdbArqatend",
action: internal.actions.internal.getAgjdbArqatendInternal
})

export const getAgjdbArqatendCachedAction = action({
handler: async (ctx): Promise<string> => {
return await getAgjdbArqatendCached.fetch(ctx, {});
}
})
'getAgjdbArqatendCached' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022) Some one can help me to understand this error? On the backend the function is working, but that type error is anoying
No description
5 Replies
ian
ian3mo ago
Add return types to the handler of what is using the cache, not just the cached action. if those are depending on the cached action type for their return values. https://github.com/get-convex/cache/blob/main/README.md#L18-L28
collin_codes_77
collin_codes_773mo ago
the cache cannot be exported for the typesafety to work
ian
ian3mo ago
I have done so successfully, so I'm curious what issue your running into and what type definitions might be necessary to help the typscript language server out. And you're on the latest version?
collin_codes_77
collin_codes_772mo ago
yes i'm on the right version i believe there's probably an import cycle of some sort
ian
ian2mo ago
Correct. The two ways of solving this are: 1. Define export const getAgjdbArqatendCached in a separate file from the action it's referencing 2. Don't export it. Just const getAgjdbArqatendCached It both impacts the internal.actions.internal type (by exporting) and depends on it (internal.actions.internal.getAgjdbArqatendInternal)

Did you find this page helpful?