Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabaseβ€’4y agoβ€’
17 replies
appixel.dev

Typescript support in V2 with reading foreign tables

Has anyone had any luck getting this to work using v2? seems like the example from the docs does not work - https://supabase.com/docs/reference/javascript/next/typescript-support#nested-tables

In my opinion this works so much better in V1 like below:

import { useQuery } from '@tanstack/react-query';

import supabase from './supabase';
import { Listing } from './types';

export async function getListings() {
  const query = `
    id,
    title,
    price,
    photos,
    seller: profiles (id, name, city, state),
    categories (name, slug)
  `;

  return supabase.from<Listing>('listings').select(query);
}

export const useGetListings = () => {
  return useQuery(['home', 'listings'], () => getListings());
};
import { useQuery } from '@tanstack/react-query';

import supabase from './supabase';
import { Listing } from './types';

export async function getListings() {
  const query = `
    id,
    title,
    price,
    photos,
    seller: profiles (id, name, city, state),
    categories (name, slug)
  `;

  return supabase.from<Listing>('listings').select(query);
}

export const useGetListings = () => {
  return useQuery(['home', 'listings'], () => getListings());
};


Using V2 as instructed in the docs but does not work
import { useQuery } from '@tanstack/react-query';

import supabase from './supabase';
import type { Database } from './database.types';

export async function getListings() {
  const response = await supabase.from('listings').select(`
    id,
    title,
    price,
    photos,
    seller: profiles (id, name, city, state),
    categories (name, slug)
  `);

  return response;
}

export const useGetListings = () => {
  return useQuery(['home', 'listings'], () => getListings());
};

type profiles = Database['public']['Tables']['profiles']['Row'];
type ListingsResponse = Awaited<ReturnType<typeof getListings>>;
export type ListingsResponseSuccess = ListingsResponse['data'] & {
  seller: profiles;
};
import { useQuery } from '@tanstack/react-query';

import supabase from './supabase';
import type { Database } from './database.types';

export async function getListings() {
  const response = await supabase.from('listings').select(`
    id,
    title,
    price,
    photos,
    seller: profiles (id, name, city, state),
    categories (name, slug)
  `);

  return response;
}

export const useGetListings = () => {
  return useQuery(['home', 'listings'], () => getListings());
};

type profiles = Database['public']['Tables']['profiles']['Row'];
type ListingsResponse = Awaited<ReturnType<typeof getListings>>;
export type ListingsResponseSuccess = ListingsResponse['data'] & {
  seller: profiles;
};
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Issue to query foreign tables
SupabaseSSupabase / help-and-questions
4y ago
Querying foreign tables w SDK
SupabaseSSupabase / help-and-questions
4y ago
error while Querying foreign tables - JS
SupabaseSSupabase / help-and-questions
4y ago
SupabaseJS v2 Typescript
SupabaseSSupabase / help-and-questions
4y ago