#Type generation and Relationships in Typescript

5 messages · Page 1 of 1 (latest)

proud trout
#

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

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

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

export type Favorite = Models.Document & {
    item: Item;
    user: User;
}
const favorite = databases.createDocument(
    ID.unique(),
    {
        item: item.$id, // Error: Type string is not assignable to type Item
        user: user.$id, // Error: Type string is not assignable to type User
    },
);

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?

marble burrow
#

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?

I think for naming we should always go with user has decided first, rather than enforcing our own assumptions. a collection can very well be named Items or just an Item. its upto the user how to use it

and its a very quick update from plural to singular

proud trout
#

@marble burrow Any updates? Issue still present in appwrite-cli 8.3.0

databases.createDocument(
    ID.unique(),
    {
        item: item.$id, // Error: Type string is not assignable to type Item
        user: user.$id, // Error: Type string is not assignable to type User
    },
);
#

@hexed sequoia