erquhart
erquhart17mo ago

Convex ID's accepted in string index equality comparators

This makes sense I guess since the ID is indeed a string, but this is becoming a regular "gotcha" as I'm walking through some internal migrations.
const legacyItem = await db
.query('items')
.withIndex('byExternalId', (q) => q.eq('externalId', itemId))
.unique()
const legacyItem = await db
.query('items')
.withIndex('byExternalId', (q) => q.eq('externalId', itemId))
.unique()
In this example, itemId is a convex ID. The externalId field expects a string - I would love some sort of option to cause this to be a type error.
2 Replies
sshader
sshader17mo ago
Feedback noted, although this is kind of hard since IDs are a subset of strings. There’s not a good type for “strings that aren’t valid convex IDs” but perhaps there are some typescript tricks we could use here
erquhart
erquhartOP17mo ago
Yeah that’s about what I figured. Thanks!

Did you find this page helpful?