【发布时间】:2018-12-12 22:58:25
【问题描述】:
我很确定我可以自己解决这个问题,但如果它可以帮助其他人,我想分享并节省其他人的时间。
我不得不添加 es6-promise 库来消除这个错误
Promise only result to a type, but is only used as a value here.
当我尝试使用 Promise.all 时(请参阅 this discussion )。到目前为止它工作得很好,当我尝试使用来自 MongoDB 的 Promise 时出现错误。
Promise<whatever> is not assignable to Promise<any>
Property 'finally' is missing in type Promise<whatever>
根据this issue on es6-promise(如果我没看错的话),新的 finally 属性正在破坏兼容性。它在 Promise Mongo 返回上,但不在我从 es6-promise 导入的那个上。
有什么想法吗?
【问题讨论】:
-
我尝试将 es6-promise 固定到 4.1.1 并简单地删除它。我使用打字稿 2.8.3
-
您是否尝试过仅使用内置的承诺定义?在 tsconfig 中:
"lib": ["es5","es2015.promise","dom", "scripthost"] -
刚试过,不行。我不愿意更新 Typescript,因为我很确定这会破坏一切
-
更新到 2.9.2,仍然无法正常工作(但看起来编译器现在默认使用
--pretty... 错误更漂亮,颜色更整洁,但它仍然存在)。 -
我并不一定建议你升级 tsc,如果你只需要 Promises 的定义,就可以使用内置的。即使在以
es5为目标时,您也可以通过使用上面的 libs 选项来执行此操作。并删除 es6-promise
标签: typescript es6-promise finally