Skip to content
Back

Type generation and Relationships in Typescript

  • 0
  • Databases
  • Web
  • Cloud
Rostlino
10 Aug, 2025, 12:25

Hello 👋, quick question about Type generation and Relationships in Typescript. There might be an "issue" using createDocument for relations, only the parameter $id is required, but the Type generation assigns whole type. What would be the ideal way to deal with it?

appwrite.d.ts

TypeScript
export type Items = Models.Document & {
    name: string;
}

export type Users = Models.Document & {
    username: string;
}

export type Favorites = Models.Document & {
    item: Items;
    user: Users;
}
TypeScript
databases.createDocument(
    ID.unique(),
    {
        item: items.$id, // Error: Type string is not assignable to type Items
        user: users.$id, // Error: Type string is not assignable to type Users
    },
);

And also, the appwrite.d.ts generator write the type name as plural (Items, Users, Favorites) instead of singular (Item, User, Favorite), is it intentional? From source code I found that it uses the collection name, but automatically creating singular from plural would be more appropriate? Is it recommended to use singular name of the collection to avoid this?

TL;DR
- Developers are facing a Type generation and Relationships issue when using `createDocument` in Typescript for relations. - Only the parameter `$id` is required, causing errors in Type assignment for `Items` and `Users`. - The suggested solution is to use the unique ID rather than the entire type when making the assignment. - The `appwrite.d.ts` generator writes type names in plural form, but it's suggested to consider using singular names to avoid confusion and ensure clarity in the code structure.
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