© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago
Charles de Dreuille

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);
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();
  }, []);
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
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to properly add types for nested tables in SvelteKit
SupabaseSSupabase / help-and-questions
4y ago
supabasejs is returning unknown type for nested tables
SupabaseSSupabase / help-and-questions
4y ago
What RLS policies to set for Supabase Queue Tables?
SupabaseSSupabase / help-and-questions
14mo ago
How to correctly set React API URL env variable for Self hosted
SupabaseSSupabase / help-and-questions
4y ago