[couchbase]: Ensure OpCallback is composable with normal callbacks (#27639)

The documentation gets weird about the API promising to return *some* kind
of value that evaluates to false, even if that might be the number zero.
The original types author expressed that as CouchbaseError | number, but
that makes it seem like the result could be some non-zero number.

I don't know whether the library actually issues callback(0) calls, but to
make it play better with normal callbacks (err?: Error), we will act as if
it uses null instead of zero.
This commit is contained in:
Brian Crowell 2018-08-01 14:05:04 -05:00 committed by Sheetal Nandi
parent f8379fa8b0
commit 3f5b9e5f0e
2 changed files with 7 additions and 2 deletions

View File

@ -31,6 +31,11 @@ bucket.manager().createPrimaryIndex(function() {
});
});
// Ensure bucket.upsert is composable with normal callbacks
function composable(callback: (err?: Error) => void) {
bucket.upsert('key', {value: 1}, callback);
}
// From https://developer.couchbase.com/documentation/server/current/sdk/nodejs/n1ql-queries-with-sdk.html
function n1ql_a() {
const n1qlquery = N1qlQuery.fromString('SELECT name, email FROM users WHERE name=$1');

View File

@ -2019,10 +2019,10 @@ declare namespace Bucket {
*/
interface OpCallback {
/**
* @param error The error for the operation. This can either be an Error object or a value which evaluates to false (null, undefined, 0 or false).
* @param error The error for the operation. This can either be an Error object or a value which evaluates to false.
* @param result The result of the operation that was executed. This usually contains at least a cas property, and on some operations will contain a value property as well.
*/
(error: CouchbaseError | number, result: any): void;
(error: CouchbaseError | null, result: any): void;
}
/**