adam
adam6mo ago

Convex 1.13.0 missing optional in types

I seem to be encountering typescript errors when upgrading to convex 1.13.0. Take await ctx.db.insert('messages', message); for example. Here is the expected type that ctx.db.insert() expects for message:
// convex: 1.12.2
// convex-helpers: 0.1.43
{
id?: string | undefined,
name?: string | undefined,
parentName?: string | undefined,
postId?: string | undefined,
author: string,
body: string
}

// convex: 1.13.0
// convex-helpers: 0.1.45
{
id: string | undefined;
name: string | undefined;
parentName: string | undefined;
postId: string | undefined;
author: string;
body: string;
}
// convex: 1.12.2
// convex-helpers: 0.1.43
{
id?: string | undefined,
name?: string | undefined,
parentName?: string | undefined,
postId?: string | undefined,
author: string,
body: string
}

// convex: 1.13.0
// convex-helpers: 0.1.45
{
id: string | undefined;
name: string | undefined;
parentName: string | undefined;
postId: string | undefined;
author: string;
body: string;
}
await ctx.db.insert('messages', { author: 'Sam', body: 'test' }); is no longer valid because I need to explicitly define id, name, postId even though they can be undefined. Is there a way to restore the previous optional behaviour?
3 Replies
Michal Srb
Michal Srb6mo ago
You included convex-helpers, what does your schema look like? Is it using convex-helpers helper?
adam
adamOP6mo ago
I'm using the zodToConvex helper like this:
export const messageSchema = z.object({
_creationTime: z.number().optional(),
_id: zid('messages').optional(),
author: z.string(),
body: z.string(),
id: z.string().uuid().optional(),
name: z.string().optional(),
parentName: z.string().default('some parent.'),
postId: z.string().optional(),
});

export default defineSchema(
{
messages: defineTable(zodToConvex(messageSchema)),
}
);
export const messageSchema = z.object({
_creationTime: z.number().optional(),
_id: zid('messages').optional(),
author: z.string(),
body: z.string(),
id: z.string().uuid().optional(),
name: z.string().optional(),
parentName: z.string().default('some parent.'),
postId: z.string().optional(),
});

export default defineSchema(
{
messages: defineTable(zodToConvex(messageSchema)),
}
);
sshader
sshader6mo ago
Thanks for the report! Working on a fix

Did you find this page helpful?