Docs
TypeScript

TypeScript

Yes, this library contains built-in TypeScript declaration.

Yes, it also uses a discriminated union type (opens in a new tab) for the query result.

const useFloppyDiskQuery = createQuery(
  () => Promise.resolve({ isAwesome: true })
);
 
function Component() {
  const { data, isLoading, isSuccess, isError } = useFloppyDiskQuery();
  //      ^? const data: { isAwesome: boolean } | undefined
 
  if (isLoading) {
    console.log(data);
    //          ^? const data: undefined
  }
 
  if (isSuccess) {
    console.log(data);
    //          ^? const data: { isAwesome: boolean }
  }
 
  if (isError) {
    console.log(data);
    //          ^? const data: undefined
  }
}