-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Changed return type of toArray
to HTMLElement[]
#11098
Conversation
Also changed the return type for `get(void)` and added a JSDoc `@alias` annotation.
jquery/jquery.d.ts to authors (@borisyankov @choffmeister @Steve-Fenton @Diullei @tasoili @jasons-novaleaf @seanski @Guuz @ksummerlin @basarat @nwolverson @derekcicerone @AndrewGaspar @jameshfisher @seikichi @benjaminjackman @s093294 @JoshStrobl @johnnyreilly @DickvdBrink). Could you review this PR? Checklist
|
Failure: https://travis-ci.org/DefinitelyTyped/DefinitelyTyped/builds/158300393#L1213 Should I be using |
Think of |
@thorn0, that's a fair point, but I feel like that is kind of a "garbage-in-garbage-out scenario". When would you need to actually use |
Could you address the failing tests please? If |
Thank you for your contribution. |
This should fix the failure reported here: https://travis-ci.org/DefinitelyTyped/DefinitelyTyped/builds/158300393#L1213
Now the __only__ return type is `HTMLElement`, which should solve the Travis build/test failure.
toArray
to Element[]
toArray
to HTMLElement[]
Ok, tests pass @johnnyreilly @sheetalkamat 🎉 I switched |
Thanks! |
Hi, having a problem with this when using in conjunction with mapping function. For instance: Expected output should be array of strings but Typescript compiler won't allow cast from HTMLElement[] to string[]. any[] used to work fine with additional casting. Please, reconsider. |
Why not first call `toArray` and map off of that? It should be equivalent,
with the benefit of still being type safe.
…On Mon, Feb 27, 2017 at 2:55 PM Andrej Galad ***@***.***> wrote:
Hi, having a problem with this when using in conjunction with mapping
function.
For instance:
$('a').map((_, a) => a.href).get()
or
$('a').map((_, a) => a.href).toArray()
Expected output should be array of strings but Typescript compiler won't
allow cast from HTMLElement[] to string[]. any[] used to work fine with
additional casting. Please, reconsider.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11098 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADhFUd7XF2ZYxPxKVQ2QKo6j7opLixK9ks5rgyotgaJpZM4J3ZMY>
.
|
Good point! In that case, maybe we could have a type parametrized (e.g.
JQueryArrayWrapper<T>) version of toArray that returns the correct result
type (e.g. T[]).
…On Mon, Feb 27, 2017 at 4:55 PM Andrej Galad ***@***.***> wrote:
Yeah, functionality-wise these notations are definitely equivalent. I just
wanted to reiterate on the fact that this change was motivated by JQuery
doc for get(void) <https://api.jquery.com/get/>, yet JQuery doc for map
<http://api.jquery.com/map/> suggests that the above should work, even
highlighting it as an example.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11098 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADhFUQGTY4GJ3v9szYVtcYFx9iA2aM0wks5rg0ZYgaJpZM4J3ZMY>
.
|
Not sure if I understood your parametrized idea but I think there are essentially 2 possible approaches.
|
We might be able to be lazier (approach 1) and take advantage of default type parameters. From my understanding, JQuery acts as a wrapper around HTMLElements (hence my belief in |
Yeah, was about to write about the default types. For backwards compatibility I would maybe suggest reverting back to |
I can make the updates soon. |
case 2. Improvement to existing type definition.
NOTE Also changed the return type for
get(void)
and added a JSDoc@alias
annotation.Documentation See
toArray()
andget(void)
.Due to legacy support, these functions are practically aliases.