T
tRPC

How to enforce usequery as NonNullable

How to enforce usequery as NonNullable

MMugetsu3/21/2023
I have a custom hook with infinite query. I check for undefined at the app first render and then it is reused so I know by then, the type should not be undefined. I would like to be able to infer its type without undefined conditionally. Can I do that? How to if so??
export const useAppContext = (enabled = true) =>
api.appContext.getAppContext.useQuery(undefined, {
staleTime: Infinity,
enabled,
select: (data) => {
currentRoles = data?.authorisation?.roles ?? []
return data
},
})
export const useAppContext = (enabled = true) =>
api.appContext.getAppContext.useQuery(undefined, {
staleTime: Infinity,
enabled,
select: (data) => {
currentRoles = data?.authorisation?.roles ?? []
return data
},
})
Nnlucas3/21/2023
The type of what is undefined?
MMugetsu3/21/2023
the type of data will be in this case always the TYPE | undefined. const { data } = useAppContext() I would like it to be: 1st time (app top level) of type -> TYPE | undefined and then force it to be just -> TYPE so I dont have to do checking for undefined or mark chaining of data property with ! as I know at this time it's already in the cache and exists
Nnlucas3/21/2023
Ah right, this is a react-query question, and I think the answer is it's not possible react-query just defines that value as possibly undefined, because in theory at any point it could be and typescript is static I guess that might change when suspense becomes a bigger thing
MMugetsu3/21/2023
Alright, I will ask tho at react-query but I see your point.

Looking for more? Join the community!

T
tRPC

How to enforce usequery as NonNullable

Join Server
Recommended Posts
How to call useQuery with params inside JSXHow can i achieve this? Thanks ``` export function MemberQueryList({ list }: Props) { function Sharing EnumOn the backend: I have colocated files with types and procedures (index.ts - procedures, schemas.ts Meta - unable to create default metaTrying to follow https://trpc.io/docs/server/metadata#default-meta-chaining-and-shallow-merging I setrpc/react-query batchingHi. How do you deal with batching? If I don't put any maxURLLength then I get an error 404 since it middleware error with minimal-react examplehello! I tried to use the minimal-react version, but I get an error - it says that `'middleware'` dohow to use the same Zod validation both client and server's procedure inputWhen submitting forms, I need the same validation. How to reduce the repeated code?pipe/unstable_pipeI cant seem to find it? according to the docs I can chain middlewares using pipe in v10 but the featImplementation of bi-directional cursor-based paginationI'm looking at the [example](https://trpc.io/docs/useInfiniteQuery#example-react-component) for `useHow to ignore `input` validation and just pass in an object with interfaces?For my input I just want to pass in an interface rather than using a Zod schema. Either that or if sWhere can I add a query key?I tried to follow as in useQuery from Tanstack, but Typescript started complaining ```js api.promptsasync inside link next handler possible ?Hey everyone, Today I had to do a bit of refactor, and I'm wondering something. I had to turn a syntRPC doesn't support redirectI use tRPC & @trpc/server/adapters/express. procdure.query({ctx: { res }} => { res.redirect('xxHow to get external key other than INPUT from RESTFUL request?SSO callback my api like api/trpc/user.login?token=abcCannot read properties of undefined (reading 'createTRPCReact')I'm trying to use it in an Astro project. https://github.com/Industrial/test-astro-solid/blob/main/application/octet-stream responseIm refactoring my old backend to trpc so far it was a pleasure and fairly straight forward process ❤Discriminated union handleHow Do I handle Input type if its discriminated union?? ``` export const batchTasksRouter = create