nakajimayoshi
nakajimayoshi2w ago

customQuery + type errors

is this supposed to happen when definiting custom functions? I have a separate file I want all my other mutations/queries to use to check auth before every request, but the moment I try exporting the custom function variable, convex throws a type error:
export const userQuery = customQuery(query, { // ERROR: <-- 'userQuery' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. (ts 7022)
args: {},
input: async (ctx, args) => {

const db = wrapDatabaseReader(ctx, ctx.db, await rlsRules(ctx));
return {
ctx: { db },
args: {},
onSuccess: ({ args, result }) => { },
};
},
});

const userQuery = customQuery(query, { // No error, but now I can't use it in my other files..
args: {},
input: async (ctx, args) => {

const db = wrapDatabaseReader(ctx, ctx.db, await rlsRules(ctx));
return {
ctx: { db },
args: {},
onSuccess: ({ args, result }) => { },
};
},
});
export const userQuery = customQuery(query, { // ERROR: <-- 'userQuery' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. (ts 7022)
args: {},
input: async (ctx, args) => {

const db = wrapDatabaseReader(ctx, ctx.db, await rlsRules(ctx));
return {
ctx: { db },
args: {},
onSuccess: ({ args, result }) => { },
};
},
});

const userQuery = customQuery(query, { // No error, but now I can't use it in my other files..
args: {},
input: async (ctx, args) => {

const db = wrapDatabaseReader(ctx, ctx.db, await rlsRules(ctx));
return {
ctx: { db },
args: {},
onSuccess: ({ args, result }) => { },
};
},
});
1 Reply
ian
ian2w ago
this is unexpected. I suspect you're defining this in the same file that you're exporting other functions from - is that the case? The most frequent issue is when a file uses internal and also exports functions. In this case, some function is depending on the custom query. and maybe the rlsRules is depending on internal? So it'd be something like internal -> someFile -> customQuery -> internal. Where when it's not exported, the type of someFile isn't depending on customQuery btw @Clever Tagline you can use customCtx in any customQuery/Mutation/Action, and all of them also support input/args - the docs aren't very instructive here

Did you find this page helpful?