我正在编写一个模块,旨在在将查询调用到数据库之前准备查询。普通 javascript 中的代码运行得很好,但是当我尝试用 Typescript 编写它时,出现了错误:Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member
我的 JavaScript 代码:
class QueryBuilder {
constructor(query) {
this.query = query;
}
sort(keyOrList, direction) {
this.query = this.query.sort(keyOrList);
return this;
}
skip(value) {
this.query = this.query.skip(value);
return this;
}
limit(value) {
this.query = this.query.limit(value);
return this;
}
then(cb) {
cb(this.query.toArray());
}
}
Run Code Online (Sandbox Code Playgroud)
打字稿中的代码:
class QueryBuilder {
public query: Cursor;
constructor(query: Cursor) {
this.query = query;
}
public …Run Code Online (Sandbox Code Playgroud)