Patch mutation function is giving me a typescript error
I'm trying to insert a document to a table in various steps. When I insert the first two pieces of data, the record is created and I push the id as searchParams so I can have access in the next form component.
And as user keep filling forms, the document needs to receive the remaining data.
This is the schema
I first insert data into the required fields
This is the function I'm trying to implement now.
This is the typescript error I'm getting in the frontend
Error is at listingId.
Any help is appreciated!
4 Replies
Two issues:
searchParams.get
might return null
if it's not in the search params. You need to check if it's null and throw or return if so - then typescript will know that from then on it's not null.
Second: the string might be an Id but it might not. If you want to be safe, pass it up as an ID and do const listingId = db.normalizeId("listings", args.listingId)
. If you don't want to be safe, you can cast it on the client as Id<"listings">
Thanks Ian, I'll try to fix it considering your response
I'm taking a good pattern with this implementation?
Ian, after normalizing the id, I get error in first parameter of the patch function
Oh, I was checking for the wrong variable
checked for normalizedListingId instead and everything is good now