Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typings for Command element find all methods #170

Merged
merged 3 commits into from
Mar 29, 2019

Conversation

edhager
Copy link
Contributor

@edhager edhager commented Mar 21, 2019

Fixes #159.

I modified the type declarations on the Command methods that operate on Element to correctly indicate when each method returns a string or string[].

…properly indicate whether the method returns a string or a string array.
@edhager edhager requested a review from jason0x43 March 21, 2019 00:44
Copy link
Member

@jason0x43 jason0x43 left a comment

Choose a reason for hiding this comment

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

This looks great. One more change would be great -- could we update getAttribute to use the same return type (attribute values are always strings or null), then remove any generics from the tests that involve getAttribute? That will clean up getAttribute and give us a test for the array value of StringResult.

…that a string or at string array is returned.
src/Command.ts Outdated
@@ -1656,8 +1656,8 @@ export default class Command<T, P = any>
* @returns The value of the attribute, or `null` if no such attribute
* exists.
*/
getAttribute<T = any>(name: string) {
return this._callElementMethod<T>('getAttribute', name);
getAttribute(name: string) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we leave the generic, but have it default to StringResult<T> instead of any? We don't actually need the generic, but removing out would cause problems for users that had been using it.

…ype as a generic to not break code that was previously using the method.
@jason0x43 jason0x43 merged commit 3cdba41 into theintern:master Mar 29, 2019
jason0x43 pushed a commit that referenced this pull request Mar 29, 2019
* Use conditional types for the Command methods that run on Element to properly indicate whether the method returns a string or a string array.

* Update the declaration of Command#getAttribute to correctly indicate that a string or at string array is returned.

* Change the declaration of Command#getAttribute to support passing a type as a generic to not break code that was previously using the method.
jason0x43 added a commit that referenced this pull request Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants