SupabaseS
Supabase6mo ago
Julius

Inferring query types without queries

Is it possible to infer the type of the data response from a query without instancing a query variable? I'm asking because I had to suppress the ESLint warning for unused variables.

Some of my queries use nested selectors, and I prefer not to write complex types manually.

import { QueryData, SupabaseClient } from '@supabase/supabase-js';
import { ordersSelector } from '../querySelectors';

declare const supabase: SupabaseClient<Database>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _ordersQuery = supabase.from('orders').select(ordersSelector).single();

export type Order = QueryData<typeof _ordersQuery>;
Was this page helpful?