Web Dev Cody
Web Dev Cody14mo ago

No clue why I'm getting this error

import { v } from 'convex/values';

import { internal } from '../_generated/api';
import { action } from '../_generated/server';

export const createPlan = action({
args: { projectIdea: v.string(), targetUser: v.string() },
handler: async (ctx, args) => {
const user = await ctx.auth.getUserIdentity();
const userId = user?.subject;

if (!userId) {
return {
error: 'no user id was found',
};
}

try {
await ctx.runMutation(internal.users.decrementCredits, {
userId,
amount: 1,
});
} catch (err) {
return {
error: 'not enough credits',
};
}

// this is saying 'planId' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)

const planId = await ctx.runMutation(
internal.plans.mutations.createInitialPlan,
{
projectIdea: args.projectIdea,
targetUser: args.targetUser,
userId: userId,
},
);

await ctx.scheduler.runAfter(
0,
internal.plans.sections.names.generateProductNamesAction,
{
planId,
},
);

await ctx.scheduler.runAfter(
0,
internal.plans.sections.colors.generateColorPaletteAction,
{
planId,
},
);

await ctx.scheduler.runAfter(
10000,
internal.plans.sections.designs.generateDesignsAction,
{
planId,
},
);

return planId;
},
});
import { v } from 'convex/values';

import { internal } from '../_generated/api';
import { action } from '../_generated/server';

export const createPlan = action({
args: { projectIdea: v.string(), targetUser: v.string() },
handler: async (ctx, args) => {
const user = await ctx.auth.getUserIdentity();
const userId = user?.subject;

if (!userId) {
return {
error: 'no user id was found',
};
}

try {
await ctx.runMutation(internal.users.decrementCredits, {
userId,
amount: 1,
});
} catch (err) {
return {
error: 'not enough credits',
};
}

// this is saying 'planId' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)

const planId = await ctx.runMutation(
internal.plans.mutations.createInitialPlan,
{
projectIdea: args.projectIdea,
targetUser: args.targetUser,
userId: userId,
},
);

await ctx.scheduler.runAfter(
0,
internal.plans.sections.names.generateProductNamesAction,
{
planId,
},
);

await ctx.scheduler.runAfter(
0,
internal.plans.sections.colors.generateColorPaletteAction,
{
planId,
},
);

await ctx.scheduler.runAfter(
10000,
internal.plans.sections.designs.generateDesignsAction,
{
planId,
},
);

return planId;
},
});
No description
7 Replies
Web Dev Cody
Web Dev CodyOP14mo ago
when I remove the return statement it all goes away
Web Dev Cody
Web Dev CodyOP14mo ago
the mutation I'm calling that returns the plan id
No description
ballingt
ballingt14mo ago
These are annoying, we're weighing options for eliminated them.
Web Dev Cody
Web Dev CodyOP14mo ago
this fixed it 🤷‍♂️
No description
ballingt
ballingt14mo ago
Does this go away if you type planId as Id<'plans'>? yeah that TypeScript gets unhappy about circular inference here: the return type of - this function you're in the middle of depends on - the type of api which depends on - the type of the function you're in the middle of you still get typechecking if you annotate this (e.g. try changing the return type of createInitialPlan, you'll get red squigglies if they don't match)
Web Dev Cody
Web Dev CodyOP14mo ago
so it's mainly just because I'm returning the ID plans from the mutation that typescript gets confused ok well just adding the type of the variable isn't too bad for now
ballingt
ballingt14mo ago
the expict annotation is the right way to solve here, it's just frustrating that that isn't documented and that it works until it doesn't

Did you find this page helpful?