Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

extending nested interface generated by supabase

I have the following Typescript interface generated by Supabase

export interface definitions {  
  Users: {
    /** Format: uuid */
    id: string;
    /**
     * Format: timestamp with time zone
     * @default now()
     */
    created_at?: string;
    /**
     * Format: uuid
     * @description Note:
     * This is a Primary Key.<pk/>
     */
  };
  Content: {
    /**
     * Format: uuid
     * @description Note:
     * This is a Primary Key.<pk/>
     */
    id: string;
    /**
     * Format: timestamp with time zone
     * @default now()
     */
    created_at?: string;
    /** Format: text */
    name: string;
    /** Format: text */
    description: string;
  };
}

This interface must not be modified as it is auto-generated.

I usually use it like this on queries:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import { definitions } from "../types/supabase";
const id = 1
let { data, error } = await supabase
  .from<definitions["Users"]>("Users").select("created_at")
  .eq("id", id);

However for this query I need to extend my interface:

let { data: Content, error } = await supabase
  .from<ContentAndUsers>("Content")
  .select(`*, Users (id, created_at)`)
  .eq("id", id);

I tried creating the interface but it gives me TS error:

interface UserContentCombo extends definitions["Content"] {
    ...definitions["Users"]
}

what is the correct syntax?
Thanks

>Solution :

I see that the error says:

An interface can only extend an identifier/qualified-name with
optional type arguments

So to give it an identifier and fix it you can define an intermediate type:

type userDefinitions = definitions['User'];

And then use that identifier:

interface UserContentCombo extends userDefinitions {}

No need of using the spread operator

TS Playground

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading