ampp
ampp6mo ago

makeFunctionReference function type

I want to get the type when i run this, i know ctx.scheduler doesn't care about type but i want to run the function in the action through the right function ctx.runQuery or runMutation/action. without having to know the function type. Wondering if there is a trick with typescript?
5 Replies
ballingt
ballingt6mo ago
I'm not sure what you mean here, @ampp could you say more? Do you want to run a query, mutation, or action from an action and you don't know ahead of time which one it is because you're saving it as a string or something? Showing some code could help here
ampp
amppOP6mo ago
const queryReference =
typeof query === "string"
? makeFunctionReference<any, any, any>(query)
: query;
const queryReference =
typeof query === "string"
? makeFunctionReference<any, any, any>(query)
: query;
after this in order to use ctx.runAction/runMutation/runQuery you need to know what the type for an if statement. the "hack" would be to run a scheduled query that accepts any of the function types.
ballingt
ballingt6mo ago
Got it, and "string" is a function that you don't know the type of? In general yes there could be a way to ctx.runAnyKindOfFunction(string) someday, but we'd want to understand what your goal is here. Other upcoming improvements could help, like codegening a list of every public function that exists. Backing up, what's your goal here? How are you getting a string for a function that you don't know the type of?
ampp
amppOP6mo ago
I've been writing a event management system, but this particular one is for a scheduled function retry during dev(so far), i don't really want to retry it in the scheduler. However im also going to have a event function registry that is db backed that i would have the names of the functions, i don't want to have to keep the type up to date manually. And it would be nice to not have to store it.
Michal Srb
Michal Srb6mo ago
I don't think we have an API exposed for this, you'll have store the function type.