Dani;D
tRPC4y ago
17 replies
Dani;

data becomes never[] when destructuring with a fallback value

Currently it doesn't seem possible to set a fallback value on a destructured
data
property, for example:

const { data = []  } = trpc.useQuery(['company.listIds']);
// expecting data to be the inferred type { id: string }[] but instead it's never[] 


// This somehow works
const query = trpc.useQuery(['company.listIds']);
const { data = [] } = query;
// data is correctly typed as { id: string }[]

The "equivalent" with pure react-query:
interface Company {
  id: string;
}
const { data = [] } = useQuery<Company[]>(['company.listIds'], someFetchFunction);
// data is correctly typed as Company[]


Does anyone know if there's a way to achieve the same behaviour of react-query in @trpc/react?
Was this page helpful?