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:
Using V2 as instructed in the docs but does not work
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;
};

