MugetsuM
tRPC3y ago
7 replies
Mugetsu

How to enforce usequery as NonNullable

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
    },
  })
Was this page helpful?