【发布时间】:2018-01-16 07:56:23
【问题描述】:
是否可以配置 sequelize,使其使用原生 es6 承诺而不是他们的 bluebird 副本?
根据他们的docs with sequelize 4,他们正在使用蓝鸟的独立副本。但我想使用原生 es6 承诺。
示例代码:
public find(selector: object): Promise<ClientEntity[]> {
// Client is of type Model<ClientModel>; see sequelize-typescript
return ClientModel.findAll(selector)
.then(res => res.map(e => e.toJSON()))
.catch(err => console.warn('PgClientModel#find', err));
}
其中显示以下错误:Type 'Bluebird<void | any[]>' is not assignable to type 'Promise<ClientEntity[]>'. Property '[Symbol.toStringTag]' is missing in type 'Bluebird<void | any[]>'。
我现在看到的选项:
- 使用蓝鸟
- 在 bluebird 的
then和catch块内,我可以通过原生 es6 承诺resolve和reject。但我实际上不喜欢这个主意。
我正在使用以下软件包
"sequelize": "^4.31.2",
"sequelize-typescript": "^0.6.2",
"typescript": "^2.6.2"
编辑:通过将返回类型更改为PromiseLike 解决。
【问题讨论】:
标签: javascript typescript sequelize.js es6-promise bluebird