【发布时间】:2019-02-04 08:04:26
【问题描述】:
我正在尝试对 promise 使用 finally 方法,但我不断收到此错误。
Property 'finally' does not exist on type 'Promise<void>'.
我查找了与此类似的问题,这些问题建议将“es2018.promise”添加到 tsconfig.js 中的“lib”数组中。这会产生以下错误:
typescript error
Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'esnext', 'dom',
'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator',
'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol',
'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string',
'es2017.intl', 'esnext.asynciterable'.
非常感谢任何帮助解决此问题!
【问题讨论】:
-
刚刚在堆栈本身上进行了测试,它可以工作。考虑提供一个minimal reproducible example 来重现该问题。
-
你使用的是什么版本的 TypeScript?直到 2.7 才添加对 ES2018 的支持:github.com/Microsoft/TypeScript/issues/20463
-
刚刚检查了它的 2.6.2,我会更新并检查它是否已解决。
-
谢谢!这已经解决了!
-
如果您在调用
finally时遇到运行时错误,那么您的运行时环境中的 Promise 实现不支持finally。 TypeScript 对此无能为力。您可以尝试安装this polyfill。
标签: angular typescript ionic-framework es6-promise