Skip to content
Back

How to use appwrite types

  • 0
  • Databases
  • Web
  • Cloud
Oli
4 Nov, 2025, 09:10

I am using appwrite types --language ts ./types to generate the types yielding something like:

TypeScript
import type { Models } from 'node-appwrite';

// This file is auto-generated by the Appwrite CLI. 
// You can regenerate it by running `appwrite types --language ts ./types`.

export enum Status {
    DRAFT = "draft",
    PUBLISHED = "published",
    CANCELLED = "cancelled"
}

export type Events = Models.Row & {
    title: string;
    description: string | null;
    startDate: string;
    endDate: string;
    location: string;
    status: Status;
    bookingLink: string | null;
    imageUrl: string | null;
}

As a consequence I can use it for server actions like this:

TypeScript
export const getEvents = async () => {
  try {
     # getting session is here
    const { tablesDB } = createSessionClient(session.value);
    const response = await tablesDB.listRows<Events>({
      databaseId: DATABASE_ID,
      tableId: EVENTS_TABLE_ID,
      queries: [Query.orderDesc("$createdAt")],
    });

    return {
      success: true,
      data: response.rows,
    };
  } catch (error) {
    return {
      success: false,
      error: error instanceof Error ? error.message : "Unbekannter Fehler",
    };
  }
};

However, using <Events> is a bit confusing as a basically create one event. So I did export type Event = Omit<Events, keyof Models.Row>;

But then I get a typerror in the server action above:

TypeScript
Type 'Event' does not satisfy the constraint 'Row'.
  Type 'Event' is missing the following properties from type 'Row': $id, $sequence, $tableId, $databaseId, and 3 more.ts(2344)
(alias) type Event = {
    title: string;
    description: string | null;
    startDate: string;
    endDate: string;
    location: string;
    status: Status;
    bookingLink: string | null;
    imageUrl: string | null;
}
import Event

I also tried to follow https://appwrite.io/docs/products/databases/rows#type-safety, but I really don't want to manually create the types.

How did you solve this?

TL;DR
Developers want to use appwrite types generated by the CLI for server actions. They created a custom 'Event' type but got a type error. The issue is that 'Event' is missing properties from 'Row'. To solve this, they need to extend the 'Event' type to include the missing properties from 'Row': ``` export type Event = Omit<Events, keyof Models.Row> & Models.Row; ```
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more