dannyelo
dannyelo5mo ago

Best way to handle this ts error using useQuery()

Hello, I want to know what advise can you give me to handle this situation when using useQuery. Example code
const customers =
useQuery(api.sales_channels.getCustomers, {
organizationId: currentOrganization?._id,
}) || []
const customers =
useQuery(api.sales_channels.getCustomers, {
organizationId: currentOrganization?._id,
}) || []
TS Error in (organizationId):
Type 'Id<"organizations"> | undefined' is not assignable to type 'Id<"organizations">'.
Type 'undefined' is not assignable to type 'Id<"organizations">'.ts(2322)
(property) organizationId: Id<"organizations">
Type 'Id<"organizations"> | undefined' is not assignable to type 'Id<"organizations">'.
Type 'undefined' is not assignable to type 'Id<"organizations">'.ts(2322)
(property) organizationId: Id<"organizations">
2 Replies
erquhart
erquhart5mo ago
You're passing a value that may be undefined, so you 'll want to use v.optional(v.id('organizations')) in the arg validator for that query
dannyelo
dannyeloOP5mo ago
Thank you @erquhart!

Did you find this page helpful?