Clever Tagline
Clever Tagline•2w ago

Issue scheduling an internal action from a helper function

I'm using Convex version 1.26.1. In one file I have an internal action defined like this:
import { internalAction } from "../../_generated/server";
import { v } from "convex/values";

export const sendInternalEmail = internalAction({
args: {
emailTo: v.union(v.string(), v.array(v.string())),
subject: v.string(),
message: v.string(),
cc: v.optional(v.union(v.string(), v.array(v.string())))
},
handler: async (_, args) => {
// logic here
}
})
import { internalAction } from "../../_generated/server";
import { v } from "convex/values";

export const sendInternalEmail = internalAction({
args: {
emailTo: v.union(v.string(), v.array(v.string())),
subject: v.string(),
message: v.string(),
cc: v.optional(v.union(v.string(), v.array(v.string())))
},
handler: async (_, args) => {
// logic here
}
})
In a different file, I have a helper function where I'm passing ctx (typed as GenericActionCtx<any>). In that function I'm trying to schedule the above action like this:
await ctx.scheduler.runAfter(0, internal.it.internalEmail.sendInternalEmail, {
emailTo: "email@example.com",
subject: "subject",
message: "message"
})
await ctx.scheduler.runAfter(0, internal.it.internalEmail.sendInternalEmail, {
emailTo: "email@example.com",
subject: "subject",
message: "message"
})
The internal.it.internalEmail.sendInternalEmail function reference is underlined, and hovering displays this error:
Type '{ sendInternalEmail: FunctionReference<"action", "internal", { cc?: string | string[] | undefined; message: string; emailTo: string | string[]; subject: string; }, null, string | undefined>; }' is missing the following properties from type 'SchedulableFunctionReference': _type, _visibility, _args, _returnType, _componentPath
Type '{ sendInternalEmail: FunctionReference<"action", "internal", { cc?: string | string[] | undefined; message: string; emailTo: string | string[]; subject: string; }, null, string | undefined>; }' is missing the following properties from type 'SchedulableFunctionReference': _type, _visibility, _args, _returnType, _componentPath
I can't see any error in this setup. Any idea why it's claiming that there's a type mismatch? For reference, here's what the kapa.ai bot said about this. Aside from the things it mentioned that were clearly not issues (e.g. passing an object instead of a function reference), I did try using ActionCtx instead of GenericActionCtx<any>, but the error was the same.
7 Replies
Convex Bot
Convex Bot•2w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart•2w ago
Pass your DataModel to GenericActionCtx instead of any Hmm although GenericActionCtx<any> would still have scheduler
Clever Tagline
Clever TaglineOP•2w ago
Yeah, it's not saying that the scheduler part is the issue. It's complaining about the internal action passed.
erquhart
erquhart•2w ago
yeah, it's saying it's an object with a key for the function you sure the file isn't named sendInternalEmail?
Clever Tagline
Clever TaglineOP•2w ago
Doh! That's it. I hadn't completed the reference to point to the function. It was pointed to the file. Very tempted to rename one of the two 😂
erquhart
erquhart•2w ago
hahaha or just make the function the default export and rename the file index.ts nope not that lol
Clever Tagline
Clever TaglineOP•2w ago
True. I don't think that I'll have any other exports from that file

Did you find this page helpful?