ibrahimyaacob
ibrahimyaacob9mo ago

convex v.id is not typesafe ?

it does't show me the table names. is it a bug ?
No description
1 Reply
sshader
sshader9mo ago
This is not a bug, but is a limitation due to v.id() being used in schema definitions as well as argument validators. Ideally the type of v.id depends on the tables defined in your schema, but this becomes circular when using v.id in schema definitions. While you don't get the auto-complete, TS will usually point out typos (e.g. v.id("myTabel")) once you pass the ID into any of the methods on ctx.db. If you want the auto-complete + type safety for argument validators, you can make something like
import { TableNames } from '../_generated/dataModel'
export const vForArgumentValidators = {
id: <T extends TableNames>(tableName: T) => {
return v.id(tableName)
},
}
import { TableNames } from '../_generated/dataModel'
export const vForArgumentValidators = {
id: <T extends TableNames>(tableName: T) => {
return v.id(tableName)
},
}
that depends on the types generated from your schema.

Did you find this page helpful?