所以我一直在努力使RXDB工作有一个新的项目,这几天开始与角CLI使用命令RXDB Angular2-CLI“无极<void>”是不能分配给类型的参数“无极<any>”
ng new <Projectname>
后
npm install rxdb
然后创建一个服务作为它在我有这条线的麻烦RXDB的例子
export class DatabaseService {
static db$: Observable<RxDatabase> = Observable.fromPromise(RxDB
.create('collectionD', adapters[useAdapter], 'myLongAndStupidPassword', true)
.then(db => {
console.log('created Database');
window['db'] = db;
db.waitForLeadership()
.then(() => {
console.log('isLeader Now');
document.title = '♛ ' + document.title;
});
console.log('DatabaseService: create Collections');
const fns = collections
.map(col => db.collection(col.name, col.schema));
return Promise.all(fns)
.then((cols) => {
collections.map(col => col.dbCol = cols.shift());
return db;
});
})
// hooks
.then(db => {
db.collections.hero.preInsert(docObj => {
const color = docObj.color;
return db.collections.hero.findOne({color}).exec()
.then(has => {
if (has != null) {
alert('another hero already has the color ' + color);
throw new Error('color already there');
}
return db;
});
});
})
.then(db => {
console.log('created collections');
return db;
})
)
我得到这个错误,当我尝试使用的WebPack
ERROR in G:/projects/src/app/services/database.service.ts (28,62): Argument of type 'Promise<void>' is not assignable to parameter of type 'Promise<any>'. Property '[Symbol.toStringTag]' is missing in type 'Promise<void>'.)
运行线28是这样的一个我下面由RXDB文档中给出的示例
static db$: Observable<RxDatabase> = Observable.fromPromise(RxDB
.create('collectionD', adapters[useAdapter], 'myLongAndStupidPassword', true)
的Vscode和ng服务都给出了相同的错误
你会介意与我们分享第28行的'src/app/services/database.service.ts'中的代码吗? – mickdev
db $'变量代表什么?它是数据库实例吗?这是一个角度服务吗?从你的代码中不清楚你试图存储在这个变量中的东西。 – AngularChef
@AngularFrance添加了更多代码,db $表示我们将从客户端数据库 –