© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
1 reply
#Oskar

How to properly add types for nested tables in SvelteKit

So based on the example from docs:
import supabase from '~/lib/supabase'
import type { Database } from '~/lib/database.types'

async function getMovies() {
  return await supabase.from('movies').select('id, title, actors(*)')
}

type actors = Database['public']['Tables']['actors']['Row']
type MoviesResponse = Awaited<ReturnType<typeof getMovies>>
type MoviesResponseSuccess = MoviesResponse['data'] & {
  actors: actors[]
}
import supabase from '~/lib/supabase'
import type { Database } from '~/lib/database.types'

async function getMovies() {
  return await supabase.from('movies').select('id, title, actors(*)')
}

type actors = Database['public']['Tables']['actors']['Row']
type MoviesResponse = Awaited<ReturnType<typeof getMovies>>
type MoviesResponseSuccess = MoviesResponse['data'] & {
  actors: actors[]
}


type MoviesResponseSuccess = any
type MoviesResponseSuccess = any

tyoe MovieResponse = any
tyoe MovieResponse = any

actors
actors
is correctly typed, but actors is just a part of whole reponse

by doing this I losing types for
movies
movies
as they becoming an
any
any
type,


Im still learning typescript and may doing an easy mistakes but I basing very much on examples from docs and other sources, and it looks like it should works, but its not.

How to do it properly?



My full +page.server.ts file looks like that:
import { error } from '@sveltejs/kit';
import { supabase } from '$lib/supabaseClient';
import type { PageServerLoad, PageServerLoadEvent } from './$types';
import type { Database } from '$lib/database.types';

export const load: PageServerLoad<{ movies }> = async ({ params }: PageServerLoadEvent) => {
    const { data: movies, error: err } = await (<RankingsResponseSuccess>supabase
        .from('movies')
        .select(
            `*, actor1 (name, slug), actor2 (name, slug),`
        )
        .eq('slug', params.slug)
        .limit(1)
        .single());
    if (err) {
        throw error(404, err.message);
    }

    if (movies) {
        return {
            movies: movies
        };
    }
};

type actor1 = Database['public']['Tables']['actors']['Row'];
type actor2 = Database['public']['Tables']['actors']['Row'];

type RankingsResponse = Awaited<ReturnType<typeof load>>;
export type RankingsResponseSuccess = RankingsResponse['movies'] & {
    actor1: actor1[],
        actor2: actor2[]
};
import { error } from '@sveltejs/kit';
import { supabase } from '$lib/supabaseClient';
import type { PageServerLoad, PageServerLoadEvent } from './$types';
import type { Database } from '$lib/database.types';

export const load: PageServerLoad<{ movies }> = async ({ params }: PageServerLoadEvent) => {
    const { data: movies, error: err } = await (<RankingsResponseSuccess>supabase
        .from('movies')
        .select(
            `*, actor1 (name, slug), actor2 (name, slug),`
        )
        .eq('slug', params.slug)
        .limit(1)
        .single());
    if (err) {
        throw error(404, err.message);
    }

    if (movies) {
        return {
            movies: movies
        };
    }
};

type actor1 = Database['public']['Tables']['actors']['Row'];
type actor2 = Database['public']['Tables']['actors']['Row'];

type RankingsResponse = Awaited<ReturnType<typeof load>>;
export type RankingsResponseSuccess = RankingsResponse['movies'] & {
    actor1: actor1[],
        actor2: actor2[]
};


Am I doing something wrong?
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

How to correctly set typescript for nested tables
SupabaseSSupabase / help-and-questions
4y ago
TS types incorrect for join tables
SupabaseSSupabase / help-and-questions
4y ago
[Updated] How to get correct types for nested fields without losing types for main object
SupabaseSSupabase / help-and-questions
4y ago
supabasejs is returning unknown type for nested tables
SupabaseSSupabase / help-and-questions
4y ago