2017-02-26 133 views
2

vscode RxDB 所以我一直在努力使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服务都给出了相同的错误

+0

你会介意与我们分享第28行的'src/app/services/database.service.ts'中的代码吗? – mickdev

+0

db $'变量代表什么?它是数据库实例吗?这是一个角度服务吗?从你的代码中不清楚你试图存储在这个变量中的东西。 – AngularChef

+0

@AngularFrance添加了更多代码,db $表示我们将从客户端数据库 –

回答

0

感谢link you sent,我设法让RxDB工作。

这是我的代码到目前为止。它创建了一个数据库和集合:

import {Component} from '@angular/core'; 

const _Promise = Promise; 
const RxDB = require('rxdb'); 
RxDB.plugin(require('pouchdb-adapter-websql')); 
Promise = _Promise; 

const heroSchema = { ... }; 

@Component({ 
    selector: 'rxdb', 
    template: `RxdbComponent` 
}) 
export class RxdbComponent { 
    constructor() { 
    RxdbComponent.createDb() 
     .then(db => RxdbComponent.createCollection(db)) 
     .then(coll => console.log(coll)); 
    } 

    static createDb() { 
    return RxDB.create('tempDB', 'websql'); 
    } 

    static createCollection(db: any) { 
    return db.collection('users', heroSchema); 
    } 
} 

你能解释一下你想在你的​​观察到的包是什么?它是数据库实例吗?集合?

可观察到的是为了发出的价值观和我真的没有看到包装内可观察到的(当然,这将使意义的集合或者数据库实例或收集点,但RXDB已经支持露出查询作为本地观察)。

+0

你可以做一个像r2工作的angular2初学者包的代码回购?所以人们可以克隆它:)我认为这是导致问题的typescipt版本之间的区别。 –

+0

我是在rxdb回购中的示例代码,这就是为什么我做了 –

+0

哈。如果你知道你想要达到什么,这将会有所帮助。 :/反正没有什么特别的关于我的堆栈。我只需要一个新的Angular应用程序和'npm install'的RxDB。从那里你可以复制粘贴我放在这里的代码,它应该工作得一样。 – AngularChef

相关问题