How to correctly set typescript for nested tables

I tried to set it up following the docs but for some reasons typescript is complaining on setProducts(data); as the function doesn't return the new types. I'm a bit confused as to what could be the best way to set this up. Any idea where I'm doing something wrong?

const [products, setProducts] = useState<ProductsResponseSuccess[]>([]);
  const supabaseClient = useSupabaseClient<Database>();

  async function getProducts() {
    return await supabaseClient.from("products").select("*, vendor(*)");
  }

  type Vendors = Database["public"]["Tables"]["vendors"]["Row"];
  type ProductsResponse = Awaited<ReturnType<typeof getProducts>>;
  type ProductsResponseSuccess = ProductsResponse["data"] & {
    vendor: Vendors;
  };

  useEffect(() => {
    async function loadData() {
      const { data } = await getProducts();
      if (data) setProducts(data);
    }
    loadData();
  }, []);
CleanShot_2022-11-16_at_18.21.42.png
Was this page helpful?