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

parent and closest type discrepancies #2056

Closed
EHadoux opened this issue Aug 19, 2021 · 3 comments · Fixed by #2057
Closed

parent and closest type discrepancies #2056

EHadoux opened this issue Aug 19, 2021 · 3 comments · Fixed by #2057

Comments

@EHadoux
Copy link

EHadoux commented Aug 19, 2021

Hey, is there a reason why parent(selector) returns a Cheerio<Element> and closest(selector) a Cheerio<Node>?
I imagine one would expect closest to be (in theory) a recursive parent.

This prevents (at compilation, without casting) the element to be a selector in functions like nextUntil.

fb55 added a commit that referenced this issue Aug 20, 2021
Makes the docs match the implementation and is in line with jQuery.

Fixes #2056
@fb55
Copy link
Member

fb55 commented Aug 20, 2021

This was a consequence of Cheerio's closest allowing a filter function to be passed (jQuery only allows a selector). I have opened #2057 that restricts a filter function to only elements, which fixes this.

@EHadoux
Copy link
Author

EHadoux commented Aug 20, 2021

Cheers for that. So it still returns a Cheerio<Node>, that's intended, right?
My initial issue is that it looks like I can do:

const stopper = $(selector1).parent(selector2);
$(selector3).nextUntil(stopper)

but not

const stopper = $(selector1).closest(selector2);
$(selector3).nextUntil(stopper)

because nextUntil accepts a Cheerio<Element> (as returned by parent) but not a Cheerio<Node> (as returned by closest). I'm not sure if that's intended or not. Sorry my previous post wasn't clear enough.

@fb55
Copy link
Member

fb55 commented Aug 20, 2021

The next release will return a Cheerio<Element>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants