In a protractor test it is possible to chain actions like "clear" and "sendKeys" on an Element like this:
element(by.id('myId')).clear().sendKeys('123456789')
I like the compact style of it. But why does it work?
According to the API Docs of webdriver.Element.clear() the return type of clear() is webdriver.promise.Promise.<void>
When i compile it with TypeScript (1.8.x), the compiler complains that there is no property called sendKeys()
on Promise
. And I think that's actually the case.
I believe this works at runtime due to the WebDriver ControlFlow Magic.
How can i extend the TypeScript Declaration File of Protractor, to reflect this ControlFlow-Magic and make my TypeScript compiler happy?
we ended up adding the function to the namespace like this
You can cast it to the type
<any>
like so:Ugly, but works without the TS complaint.