Skip to content

Better type definitions #511

Open
Open
@trulysinclair

Description

@trulysinclair

Feature request

Is your feature request related to a problem? Please describe.

The types generated by the CLI should have multiple interfaces/types instead of nested types to improve usability.

Currently we have to use createClient<Database>(...) and for explicitly typing return types we have to use Database['public']['Tables']['...']['Row']

Describe the solution you'd like

By giving us multiple defined types/interfaces we could just use TodoTableRow or TodoTableInsert for example.

type PartialRequired<T, K extends keyof T> = Partial<T> & Pick<T, K>;

export type Json =
  | string
  | number
  | boolean
  | null
  | { [key: string]: Json }
  | Json[];

export interface Database {
  public: {
    Tables: Tables;
    Functions: {};
  }
}

export interface ProfilesTable {
  id: string;
  created_at: string | null;
  updated_at: string | null;
  installation_id: number | null;
  name: string | null;
}

export interface Tables {
  profiles: {
    Row: ProfilesTable;
    Insert: PartialRequired<ProfilesTable, 'id'>;
    Update: Partial<ProfilesTable>;
  };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions