[英]Typescript complains on promise.then
Consider following code: 考虑以下代码:
Promise.resolve('hello')
.then(a => console.log(a))
.catch(() => console.log("error"))
.then(() => console.log("ok"));
This gets me a very annoying error: 这让我有一个非常烦人的错误:
supplied parameters do not match any signature of call target: expected 0 parameter(s) but was called with 1 parameter(s) 提供的参数与调用目标的任何签名都不匹配:预期的0个参数但是使用1个参数调用
Note that I only get this for the first .then(...)
, the catch and the second then are apparently no problem. 请注意,我只在第一个.then(...)
得到这个,然后捕获和第二个显然没有问题。
Just for the record; 仅供记录; the code works and outputs 代码工作和输出
hello
ok
Maybe I should also mention that it actually compiles. 也许我还应该提一下它实际编译。 I see the error in Visual Studio 2017. When I go to the definition of then it opens lib.es6.d.ts . 我看到在Visual Studio 2017年的错误,当我去的,然后定义它打开lib.es6.d.ts。 Compilation happens with webpack 4 that uses TypeScript 2.8.3. 使用TypeScript 2.8.3的webpack 4进行编译。 In Visual Sudio I have installed TypeScript 2.8.1 (Can't find 2.8.3) 在Visual Sudio中我安装了TypeScript 2.8.1(找不到2.8.3)
If someone could explain to me why this happens. 如果有人能向我解释为什么会这样。 And even better, how to get rid of it; 甚至更好,如何摆脱它; that would be much appreciated. 非常感谢。
I had the same issue and as the comment by @JBC alluded, it's caused by ReSharper. 我有同样的问题,正如@JBC的评论暗示的那样,它是由ReSharper引起的。 In my case I was running a rather old version (2017.1.1) so updating to the latest (or disabling it altogether) fixed it. 在我的情况下,我运行了一个相当旧的版本(2017.1.1),所以更新到最新(或完全禁用它)修复它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.