-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
…properly indicate whether the method returns a string or a string array.
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
* 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.
Fixes #159.
I modified the type declarations on the
Command
methods that operate onElement
to correctly indicate when each method returns astring
orstring[]
.