14 Replies
ID class on what? on a table in your schema?
yeah
uh
the params.id will be highlighed red. it should acceppt a v.id('document')
oh okay
where are you getting params.id from?
url
yeah url
it does not accept the id as string but a v.id() which is idk something else apparently
v.id is just a typeSafe way for the id to be called. You could convert the url parem.id from a string to _id
have you tired to do it even with the error?
because i think the ids are just strings under the hood
if I do params.id as Id<'document'> I will get an validator error
thats my vscode error: Type 'string' is not assignable to type 'Id<"document">'.
Type 'string' is not assignable to type '{ __tableName: "document"; }'.ts(2322)
but
wait there must be a convert method for this lemme check the docs
Sure but I found nothing
maybe just cast it?
as Id<document> ?
The thread here https://discord.com/channels/1019350475847499849/1141866166126649354 asks a similar question.
There's not a way to tell if a string is an ID from the client, so you can either assume the string is an ID (and use
v.id("myTable")
which will throw when it's not, and myId as Id<"myTable">
to make TypeScript happy), or you can check if the string is a valid ID in a convex function and handle the case where it's not on the client
Here's a snippet of what that second approach might look like: