mako
mako
TtRPC
Created by mako on 4/25/2023 in #❓-help
Skipping useQuery with typescript
I was hoping there was another why which I was missing.
8 replies
TtRPC
Created by mako on 4/25/2023 in #❓-help
Skipping useQuery with typescript
Yes, I can make the types pass with assertions, but keeping 2 arguments in sync is both inconvenient and error prone.
8 replies
TtRPC
Created by mako on 4/25/2023 in #❓-help
Skipping useQuery with typescript
With rtk-query style skip token this would look like
const result = trpc.endpoint.useQuery(param ? { param } : skipToken)
const result = trpc.endpoint.useQuery(param ? { param } : skipToken)
Which can pass type-checking because skipToken is a valid arg to useQuery
8 replies
TtRPC
Created by mako on 4/25/2023 in #❓-help
Skipping useQuery with typescript
If you have an optional parameter to a component and need to run a query conditionally like
const result = trpc.endpoint.useQuery({ param }, { enabled: !!param })
const result = trpc.endpoint.useQuery({ param }, { enabled: !!param })
It will fail the typecheck because { param: undefined } is not a valid query
8 replies