mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Fix callback and Promise resolve type (#20404)
* Fix callback and Promise resolve Promise and callback should resolve Core.Document<Model>, not just Core.Response * Update pouchdb-upsert-tests.ts * fix version format * Down the version to 2.4
This commit is contained in:
Vendored
+7
-7
@@ -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 <https://github.com/keithdmoore>, Andrew Mitchell <https://github.com/hotforfeature>
|
||||
// Definitions by: Keith D. Moore <https://github.com/keithdmoore>, Andrew Mitchell <https://github.com/hotforfeature>, Eddie Hsu <https://github.com/apolkingg8>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
/// <reference types="pouchdb-core" />
|
||||
|
||||
@@ -20,7 +20,7 @@ declare namespace PouchDB {
|
||||
* If the document does not already exist, then {} will be the input to diffFunc.
|
||||
*
|
||||
*/
|
||||
upsert<Model>(docId: Core.DocumentId, diffFun: UpsertDiffCallback<Content & Model>): Promise<Core.Response>;
|
||||
upsert<Model>(docId: Core.DocumentId, diffFun: UpsertDiffCallback<Content & Model>): Promise<Core.Document<Model>>;
|
||||
|
||||
/**
|
||||
* 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<Model>(docId: Core.DocumentId, diffFun: UpsertDiffCallback<Content & Model>,
|
||||
callback: Core.Callback<Core.Response>): void;
|
||||
callback: Core.Callback<Core.Document<Model>>): 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<Model>(doc: Core.Document<Content & Model>): Promise<Core.Response>;
|
||||
putIfNotExists<Model>(doc: Core.Document<Content & Model>): Promise<Core.Document<Model>>;
|
||||
|
||||
//
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ declare namespace PouchDB {
|
||||
* will return a Promise.
|
||||
*/
|
||||
putIfNotExists<Model>(doc: Core.Document<Content & Model>,
|
||||
callback: Core.Callback<Core.Response>): void;
|
||||
callback: Core.Callback<Core.Document<Model>>): void;
|
||||
}
|
||||
|
||||
type UpsertDiffCallback<Content extends {}> = (doc: Core.Document<Content>) => Core.Document<Content> | boolean;
|
||||
|
||||
@@ -12,7 +12,7 @@ function testUpsert_WithPromise_AndReturnDoc() {
|
||||
db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
// Make some updates....
|
||||
return doc;
|
||||
}).then((res: PouchDB.Core.Response) => {
|
||||
}).then((res: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ function testUpsert_WithPromise_AndReturnBoolean() {
|
||||
db.upsert<UpsertDocModel>(docToUpsert._id, (doc: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
// Make some updates....
|
||||
return false;
|
||||
}).then((res: PouchDB.Core.Response) => {
|
||||
}).then((res: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ function testUpsert_WithCallback_AndReturnDoc() {
|
||||
db.upsert<UpsertDocModel>(docToUpsert._id, (doc: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
// Make some updates....
|
||||
return doc;
|
||||
}, (res: PouchDB.Core.Response) => {});
|
||||
}, (res: PouchDB.Core.Document<UpsertDocModel>) => {});
|
||||
}
|
||||
|
||||
function testUpsert_WithCallback_AndReturnBoolean() {
|
||||
@@ -36,13 +36,13 @@ function testUpsert_WithCallback_AndReturnBoolean() {
|
||||
db.upsert<UpsertDocModel>(docToUpsert._id, (doc: PouchDB.Core.Document<UpsertDocModel>) => {
|
||||
// Make some updates....
|
||||
return false;
|
||||
}, (res: PouchDB.Core.Response) => {});
|
||||
}, (res: PouchDB.Core.Document<UpsertDocModel>) => {});
|
||||
}
|
||||
|
||||
function testPutIfNotExists_WithPromise() {
|
||||
db.putIfNotExists(docToUpsert).then((res: PouchDB.Core.Response) => {});
|
||||
db.putIfNotExists(docToUpsert).then((res: PouchDB.Core.Document<UpsertDocModel>) => {});
|
||||
}
|
||||
|
||||
function testPutIfNotExists_WithCallback() {
|
||||
db.putIfNotExists(docToUpsert, (res: PouchDB.Core.Response) => {});
|
||||
db.putIfNotExists(docToUpsert, (res: PouchDB.Core.Document<UpsertDocModel>) => {});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user