Query type definition does not include all possible return scenarios
My query function is not returning all the possible values as a type definition (i.e. fullReportWithUser below), is this something I need to manually add with manual types or am I doing something wrong?
Thanks
35 Replies
I don't see anything wrong with the code. What does the type look line now, and what do you expect? What is the type of
fullReport
and report
in the return
statements?strange that reportUser is not showing as a type in the returned const
fullReport and report types are correct within the query code
but the types don't reflect in the useQuery frontend retunr
Can you hover over and screenshot:
fullReport
, fullReportWithUser
and report
in the return statements
report
on the LHS of the useQuery
callfullReportWithUser
fullReport
report
report from useQuery on frontend
Basic things to try in order:
1. Save the query file
2. make sure your
convex dev
is successful
3. restart TS server in VS Codeyep tried these already, convex dev is running and saving functions as expected
I resorted to using another query to get admin details
it's strange I remember this working fine in the past
I can reproduce it at least, something weird is indeed going on.
It's a TS bug. You can work around it by using ternaries instead of if statements:
GitHub
If statement return type with union inferred incorrectly · Issue #5...
🔎 Search Terms union, spread, return, inferrence 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about union, spread return ...
thanks, it still doesn't look like it works with layered terneries
same issue with this
ts explorer:
that _object type definition doesn't carry over
not seen this before, very strange
That code works for me. Are you on latest stable TS version? (you can tell by clicking the {} button on the bottom of TS)
5.4.5 yep
What do you see when you hover
getReport
?Can you share the reports schema so I can get a closer repro
Can you try again with this code? This one works but doesn't match your screenshot with the type of
getReport
I just broke apart some of the ternary steps to check type defs but sure
must just be an issue on my end if you cant reproduce
Yeah that looks good
The second type is hidden in the
...
but then on the frontend 😖
pain
Yeah it doesn't show up in the typeahead but the union is there
perfect, thank you
would be ideal if it recognised without it being forced into it
So it is kinda a hard-to-work-with type even when it works correctly, you might want to use a tagged union or always set reportUser.
this is great though thanks Michal
great idea