简体   繁体   中英

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)

Note that I only get this for the first .then(...) , the catch and the second then are apparently no problem.

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 . Compilation happens with webpack 4 that uses TypeScript 2.8.3. In Visual Sudio I have installed TypeScript 2.8.1 (Can't find 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. In my case I was running a rather old version (2017.1.1) so updating to the latest (or disabling it altogether) fixed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM