Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

chore(types): fix transpile errors related to IThenable #3650

Merged
merged 2 commits into from
Oct 25, 2016

Conversation

cnishina
Copy link
Member

No description provided.

@cnishina cnishina changed the title chore(types): fix types related to IThenable chore(types): fix transpile errors related to IThenable Oct 20, 2016
function loadMocks(angularVersion: number) {
if (angularVersion === 1) {
function loadMocks(angularVersion: string) {
if (angularVersion == '1') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testForAngular returns ver as number. This line is where string needs to be replaced with number.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is to satisfy TypeScript, loadMocks must have a string value. Also, since angularVersion is a string, it must then be compared to a string value. After the files are transpiled, the value '1' and 1 should not matter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why must loadMocks have a string value? Because it's inferred from the type of the angularTestResult variable whose type is wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Thanks! Fixed.

@@ -61,7 +64,7 @@ export class DriverProvider {
if (driver.getSession() === undefined) {
deferred.resolve();
} else {
driver.getSession().then((session_: string) => {
driver.getSession().then((session_: Session) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just delete this type annotation? The compiler is able to infer the type of session_.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

});
// Resolve the list of Promise<List<child_web_elements>> and merge
// into a single list
return wdpromise.all(childrenPromiseList).then((resolved: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why any? resolved seems to be WebElement[][]. But again I think it's better just to delete the type annotations here. Excessive type annotations are a kind of type assertions, they prevent the compiler from doing its job of finding type errors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the types.

return wdpromise.all(childrenPromiseList).then((resolved: any) => {
return resolved.reduce(
(childrenList: WebElement[],
resolvedE: webdriver.WebElement) => {
Copy link
Contributor

@thorn0 thorn0 Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These annotations seem to be wrong and excessive too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Removed the types.

return fn(actionResults[0]);
}, errorFn);
};
this.then =
Copy link
Contributor

@thorn0 thorn0 Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function should be made generic as well as the other then functions above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer to @juliemr

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good case for generics, because we don't actually know what value it will return based on the arguments to the function - it's based on what has been called in the chain.

@cnishina
Copy link
Member Author

Thanks @thorn0 for the review! 🎉

return fn(actionResults[0]);
}, errorFn);
};
this.then =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good case for generics, because we don't actually know what value it will return based on the arguments to the function - it's based on what has been called in the chain.

@cnishina cnishina merged commit e6475ae into angular:master Oct 25, 2016
cnishina added a commit to cnishina/protractor that referenced this pull request Oct 25, 2016
@cnishina cnishina deleted the transpile_issues branch November 7, 2016 23:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants