TeosT
Convex Community2y ago
17 replies
Teos

convex-helpers `Table` helper loses type safety

Hello, Convex community!

First off, I want to express my admiration for Convex. I'm genuinely impressed by the onboarding process and the developer experience. It's been a delight working with the stack!

However, I've run into a puzzling issue while exploring Convex, specifically related to type inference in TypeScript, and I'm hoping someone might help shed some light on it.

In my project, I have a users.ts file that defines a User table using Convex's helper functions, like so:
https://ibb.co/BwVsx0G

in my schema.ts I use it as follows :
https://ibb.co/N7QnHyB

Here's the issue, on the user.ts file, if I hover-over the User type TS infers it as object of [x: string]: any
https://ibb.co/fdx5GhK

Hovering over the schema.users the type is like the below :
https://ibb.co/8mQ9tLF

Strangely, if I skip the Table() convex-helper and i export the userFields and directly use them in the schema.ts file with defineTable(userFields) <-- the types are inferred correctly (see below):

https://ibb.co/xJLMGBS

What am I doing wrong here ?
Any insights or guidance would be greatly appreciated.
Thanks in advance for your help!
ImgBB
Image 1 hosted in ImgBB
1 hosted at ImgBB
ImgBB
Image 2 hosted in ImgBB
2 hosted at ImgBB
ImgBB
Image 3 hosted in ImgBB
3 hosted at ImgBB
ImgBB
Image 4 hosted in ImgBB
4 hosted at ImgBB
ImgBB
Image 5 hosted in ImgBB
5 hosted at ImgBB
Was this page helpful?