类型"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