Skip to content
Back

Bug Report: Issue with `createDocument` Key Suggestions

  • 0
  • General
M Zeeshan
16 Dec, 2024, 04:53

Hi there,

While coding, I noticed that createDocument doesn't provide product key suggestions in the data argument. According to your type definitions, it seems like it should suggest keys, but it doesn't.

Here's the code I was trying:

TypeScript
await databases.createDocument<Product>(
  appwriteConfig.DATABASE_ID,
  appwriteConfig.PRODUCTS_COLLECTION_ID,
  ID.unique(),
  {},
);

Here's the Product interface I'm using:

TypeScript
export interface Product extends Models.Document {
  name: string;
  description: Description;
  category: Category;
  brand: Brand;
  images: string[];
  videoUrl: string | null;
  variants: Variant[];
  weight: number;
  averageRating: number | null;
  reviewCount: number | null;
  active: boolean;
  featured: boolean;
  returnPolicy: ReturnPolicy;
  store: Store;
}

And here’s your type for createDocument:

TypeScript
createDocument<Document extends Models.Document>(
  databaseId: string, 
  collectionId: string, 
  documentId: string, 
  data: Omit<Document, keyof Models.Document>, 
  permissions?: string[]
): Promise<Document>;

Since Product extends Models.Document, I expected data to suggest the keys for the Product type (excluding Models.Document keys), but that doesn’t happen. Could you help clarify this? Is this a type inference issue, or am I missing something?

TL;DR
Issue: `createDocument` is not providing key suggestions for the `Product` interface in the `data` argument. Solution: This is not a bug, but rather a limitation with TypeScript's type inference. The `createDocument` method does not currently support suggesting keys from interfaces when using generics. This behavior is due to TypeScript restrictions and not an error in your code.
M Zeeshan
16 Dec, 2024, 04:57

issue i am experiencing is related to node-appwrite version ^14.1.0

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