Hi, we are trying Couchbase “couchbase”: “3.2.5” with couchbase v7 and TypeScript.
We got some problem with key query.
with sample bucket gamesim-sample, I have create a new VIEW
function (doc, meta) {
if (doc.jsonType == "player" && doc.loggedIn != null) {
emit([doc.loggedIn, doc.name], null);
}
}
then try with nodejs.
method A: with nodejs, I can get the correct search result
var bucket = cluster.bucket('gamesim-sample')
const viewResult = await bucket.viewQuery(
"players_update",
"playerlist",
{
timeout:10000,
stale: "false",
// keys: [[true, "Aaron0"]] // ok
key: Array.from([true, "Aaron0"]) // ok
}
).catch((e)=>{console.log(e); throw e;});
viewResult.rows.forEach((row)=>{
console.log(row);
});
ViewRow { value: null, key: [ true, 'Aaron0' ], id: 'Aaron0' }
method B: switch the same code to TypeScript. I will get a type assignment error
Type '(string | boolean)[]' is not assignable to type 'string'.ts(2322)
is it a bug or any other workaround to resolve this issue? also for keys
query.
in the type definition viewtypes.d.ts
, I can see the type is declared as a string
export interface ViewQueryOptions {
/**
* Specifies a specific key which should be fetched from the index.
*/
key?: string;
/**
* Specifies a list of keys which should be fetched from the index.
*/
keys?: string[];
}