-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Promise type does not flow generic type to then'able callback functions #3636
Comments
I cloned the repo you linked in #3637, and I'm not sure what's going on. You might have an issue with your |
I have found the problem. It's a regression with the selenium-webdriver type declarations. Specifically the The problem was introduced by the commit "types(selenium-webdriver): revert 2.44 as default". Maybe @cnishina should be looking into this as he was the committer? Before (working)Before the commit you can see the signature of the callback functions flowing the generic type from the containing Promise: After (not working)This is the function signature after the offending commit: |
That's awesome, thanks for digging into this! I may have been a bit hasty to close #3637, but I suspected the issue was the signature of then() on WebDriver's Promise not satisfying the interface for async/await. Based on those commits, it looks like that is what's happening. For anyone reading this in the future, the discussion in TypeScript #5911 is a good introduction to issues around async/await and type signatures. Correct me if I'm wrong, but it looks like the new webdriver promise typings don't match the Promise interface in typescript. The fact that they don't respect generics would also explain why TypeScript doesn't consider them to have the right "then()" for async/await. I'll get with @cnishina about fixing this. It seems like we're one of the first major projects to use selenium webdriver with TypeScript, so we've been doing a lot of unexpected maintenance on their typings. |
Agreed it doesn't match. Of course it does satisfy the interface otherwise it wouldn't compile... So hopefully looking into might resolve issue #3637 |
Hi everyone, I have problems with map function definition and how it behaves with incoming promises. public allColumnHeadersPromise() {
return element
.all(by.css('[id$="_table-header"]'))
.getText();
} Here I clearly see returning type as public allColumnHeadersPromise() {
return element
.all(by.css('[id$="_table-header"]'))
.map(e => e.getText())
} Now I got returning type as I don't know should I create separate issue for this case.
|
So the problem was in the @types/selenium-webdriver. It was fixed in version @types/[email protected] by this commit: DefinitelyTyped/DefinitelyTyped@4b4beff |
Thanks for the update! For anyone following along, if you're having this problem just do |
Bug report
6.2.2
4.0.9
1.5.8
Best to explain with some code...
Here's the code I have to write:
Here's the code I would like to write:
The type declaration for
Promise
/IThenable
should "flow" its generic type parameter to the signature of it'sthen
able callback function parameter.Instead, as you can see from the first example, I'm having to explicitly add a type annotation for the
val
parameter.The text was updated successfully, but these errors were encountered: