From 55b81a75c508d685feca39e38ebe071820cafde1 Mon Sep 17 00:00:00 2001 From: Demiurga Date: Tue, 17 Oct 2017 02:13:13 +0800 Subject: [PATCH] Fix callback and Promise resolve type (#20404) * Fix callback and Promise resolve Promise and callback should resolve Core.Document, not just Core.Response * Update pouchdb-upsert-tests.ts * fix version format * Down the version to 2.4 --- types/pouchdb-upsert/index.d.ts | 14 +++++++------- types/pouchdb-upsert/pouchdb-upsert-tests.ts | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/types/pouchdb-upsert/index.d.ts b/types/pouchdb-upsert/index.d.ts index e893a052aa..0a71b0383d 100644 --- a/types/pouchdb-upsert/index.d.ts +++ b/types/pouchdb-upsert/index.d.ts @@ -1,8 +1,8 @@ -// Type definitions for pouchdb-upsert 2.0 +// Type definitions for pouchdb-upsert 2.2 // Project: https://github.com/pouchdb/upsert -// Definitions by: Keith D. Moore , Andrew Mitchell +// Definitions by: Keith D. Moore , Andrew Mitchell , Eddie Hsu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.4 /// @@ -20,7 +20,7 @@ declare namespace PouchDB { * If the document does not already exist, then {} will be the input to diffFunc. * */ - upsert(docId: Core.DocumentId, diffFun: UpsertDiffCallback): Promise; + upsert(docId: Core.DocumentId, diffFun: UpsertDiffCallback): Promise>; /** * Perform an upsert (update or insert) operation. If a callback is not provided, the Promise based version @@ -33,7 +33,7 @@ declare namespace PouchDB { * @param callback - called with the results after operation is completed. */ upsert(docId: Core.DocumentId, diffFun: UpsertDiffCallback, - callback: Core.Callback): void; + callback: Core.Callback>): void; /** * Put a new document with the given docId, if it doesn't already exist. Returns a Promise. @@ -41,7 +41,7 @@ declare namespace PouchDB { * @param doc - the document to insert. Should contain an _id if docId is not specified * If the document already exists, then the Promise will just resolve immediately. */ - putIfNotExists(doc: Core.Document): Promise; + putIfNotExists(doc: Core.Document): Promise>; // /** @@ -55,7 +55,7 @@ declare namespace PouchDB { * will return a Promise. */ putIfNotExists(doc: Core.Document, - callback: Core.Callback): void; + callback: Core.Callback>): void; } type UpsertDiffCallback = (doc: Core.Document) => Core.Document | boolean; diff --git a/types/pouchdb-upsert/pouchdb-upsert-tests.ts b/types/pouchdb-upsert/pouchdb-upsert-tests.ts index c3d261bb5c..a441f76ab4 100644 --- a/types/pouchdb-upsert/pouchdb-upsert-tests.ts +++ b/types/pouchdb-upsert/pouchdb-upsert-tests.ts @@ -12,7 +12,7 @@ function testUpsert_WithPromise_AndReturnDoc() { db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { // Make some updates.... return doc; - }).then((res: PouchDB.Core.Response) => { + }).then((res: PouchDB.Core.Document) => { }); } @@ -20,7 +20,7 @@ function testUpsert_WithPromise_AndReturnBoolean() { db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { // Make some updates.... return false; - }).then((res: PouchDB.Core.Response) => { + }).then((res: PouchDB.Core.Document) => { }); } @@ -28,7 +28,7 @@ function testUpsert_WithCallback_AndReturnDoc() { db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { // Make some updates.... return doc; - }, (res: PouchDB.Core.Response) => {}); + }, (res: PouchDB.Core.Document) => {}); } function testUpsert_WithCallback_AndReturnBoolean() { @@ -36,13 +36,13 @@ function testUpsert_WithCallback_AndReturnBoolean() { db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { // Make some updates.... return false; - }, (res: PouchDB.Core.Response) => {}); + }, (res: PouchDB.Core.Document) => {}); } function testPutIfNotExists_WithPromise() { - db.putIfNotExists(docToUpsert).then((res: PouchDB.Core.Response) => {}); + db.putIfNotExists(docToUpsert).then((res: PouchDB.Core.Document) => {}); } function testPutIfNotExists_WithCallback() { - db.putIfNotExists(docToUpsert, (res: PouchDB.Core.Response) => {}); + db.putIfNotExists(docToUpsert, (res: PouchDB.Core.Document) => {}); }