Skip to content

Commit 53f58ac

Browse files
committed
Fix autocomplete for Databases.createDocument
Fixes #76 Update `createDocument` method to improve TypeScript autocompletion. * **src/models.ts** - Remove the string index signature from `Models.Document`. - Add a new type `AnyDocument` extending `Models.Document` with the string index signature. * **src/services/databases.ts** - Update `createDocument` method to use `T extends Models.Document = Models.AnyDocument`. - Update `data` parameter type to `Omit<T, keyof Models.Document>`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/appwrite/sdk-for-web/issues/76?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 3bb1cfa commit 53f58ac

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/models.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export namespace Models {
5555
logs: Log[];
5656
}
5757
/**
58-
* Files List
59-
*/
58+
* Files List
59+
*/
6060
export type FileList = {
6161
/**
6262
* Total number of files documents that matched your query.
@@ -212,6 +212,11 @@ export namespace Models {
212212
* Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
213213
*/
214214
$permissions: string[];
215+
}
216+
/**
217+
* AnyDocument
218+
*/
219+
export interface AnyDocument extends Document {
215220
[key: string]: any;
216221
}
217222
/**
@@ -978,8 +983,8 @@ export namespace Models {
978983
code: string;
979984
}
980985
/**
981-
* Language
982-
*/
986+
* Language
987+
*/
983988
export type Language = {
984989
/**
985990
* Language name.

src/services/databases.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ export class Databases {
5454
* @param {string} databaseId
5555
* @param {string} collectionId
5656
* @param {string} documentId
57-
* @param {Omit<Document, keyof Models.Document>} data
57+
* @param {Omit<T, keyof Models.Document>} data
5858
* @param {string[]} permissions
5959
* @throws {AppwriteException}
60-
* @returns {Promise<Document>}
60+
* @returns {Promise<T>}
6161
*/
62-
async createDocument<Document extends Models.Document>(databaseId: string, collectionId: string, documentId: string, data: Omit<Document, keyof Models.Document>, permissions?: string[]): Promise<Document> {
62+
async createDocument<T extends Models.Document = Models.AnyDocument>(databaseId: string, collectionId: string, documentId: string, data: Omit<T, keyof Models.Document>, permissions?: string[]): Promise<T> {
6363
if (typeof databaseId === 'undefined') {
6464
throw new AppwriteException('Missing required parameter: "databaseId"');
6565
}

0 commit comments

Comments
 (0)