From c722838e0102afa8d065d053a841149fbe9a6b8a Mon Sep 17 00:00:00 2001 From: Demiurga Date: Thu, 19 Oct 2017 00:13:36 +0800 Subject: [PATCH] fix wrong pr #20404 (#20676) * fix wrong pr #20404 * fix wrong pr #20404 * Update pouchdb-upsert-tests.ts * Use interface instead of a type literal * Missing semicolon * Use Core.DocumentId, Core.RevisionId instead of string --- types/pouchdb-upsert/index.d.ts | 14 ++++++++++---- types/pouchdb-upsert/pouchdb-upsert-tests.ts | 12 ++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/types/pouchdb-upsert/index.d.ts b/types/pouchdb-upsert/index.d.ts index 0a71b0383d..60b2409ff0 100644 --- a/types/pouchdb-upsert/index.d.ts +++ b/types/pouchdb-upsert/index.d.ts @@ -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,10 +55,16 @@ 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; + + interface UpsertResponse { + id: Core.DocumentId; + rev: Core.RevisionId; + updated: boolean; + } } declare module 'pouchdb-upsert' { diff --git a/types/pouchdb-upsert/pouchdb-upsert-tests.ts b/types/pouchdb-upsert/pouchdb-upsert-tests.ts index a441f76ab4..55697e88d6 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.Document) => { + }).then((res: PouchDB.UpsertResponse) => { }); } @@ -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.Document) => { + }).then((res: PouchDB.UpsertResponse) => { }); } @@ -28,7 +28,7 @@ function testUpsert_WithCallback_AndReturnDoc() { db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { // Make some updates.... return doc; - }, (res: PouchDB.Core.Document) => {}); + }, (res: PouchDB.UpsertResponse) => {}); } 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.Document) => {}); + }, (res: PouchDB.UpsertResponse) => {}); } function testPutIfNotExists_WithPromise() { - db.putIfNotExists(docToUpsert).then((res: PouchDB.Core.Document) => {}); + db.putIfNotExists(docToUpsert).then((res: PouchDB.UpsertResponse) => {}); } function testPutIfNotExists_WithCallback() { - db.putIfNotExists(docToUpsert, (res: PouchDB.Core.Document) => {}); + db.putIfNotExists(docToUpsert, (res: PouchDB.UpsertResponse) => {}); }