类型"Promise< void>"上不存在属性"finally" [英] Property 'finally' does not exist on type 'Promise<void>'

查看:637
本文介绍了类型"Promise< void>"上不存在属性"finally"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在诺言中尝试使用finally方法,但是我一直收到此错误.

I am trying to use the finally method on a promise but I keep getting this error.

Property 'finally' does not exist on type 'Promise<void>'.

我查找了与此类似的问题,这些问题建议在tsconfig.js中的"lib"数组中添加"es2018.promise".然后,将产生以下错误:

I have looked up similar questions to this which have suggested adding "es2018.promise" to the "lib" array in tsconfig.js. This then produces the following error:

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'.

任何帮助解决此问题的方法,将不胜感激!

Any help resolving this is greatly appreciated!

推荐答案

对于TypeScript 3.3.3,只需将es2018.promise添加到您的tsconfig.json-compilerOptions.lib配置中,如下所示:

For TypeScript 3.3.3, just add es2018.promise to your tsconfig.json - compilerOptions.lib config like this:

"lib": ["es2015", "es2016", "dom", "es2018.promise"]

如果使用vscode,则在将此选项添加到tsconfig.json文件后,也许应该reload window

If you use vscode, maybe you should reload window after adding this option to your tsconfig.json file

这篇关于类型"Promise&lt; void&gt;"上不存在属性"finally"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆