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

Update querySelector type definition to return null #157

Closed
johnnyoshika opened this issue Sep 30, 2021 · 4 comments
Closed

Update querySelector type definition to return null #157

johnnyoshika opened this issue Sep 30, 2021 · 4 comments
Labels

Comments

@johnnyoshika
Copy link

The TypeScript return type for querySelector() is HTMLElement instead of HTMLElement | null. querySelector() can potentially return null if no elements are found. This will allow code that could throw a null reference exception to pass the type checker.

Relevant type definition:

    /**
     * Query CSS Selector to find matching node.
     * @param  {string}         selector Simplified CSS selector
     * @return {HTMLElement}    matching node
     */
    querySelector(selector: string): HTMLElement;

public querySelector(selector: string) {
return selectOne(selector, this as HTMLElement, {
xmlMode: true,
adapter: Matcher

Can you set the return type to HTMLElement | null?

@nonara
Copy link
Collaborator

nonara commented Sep 30, 2021

Good catch! Thanks for the heads up, Johnny.

@nonara nonara added the bug label Sep 30, 2021
@johnnyoshika
Copy link
Author

@nonara Thank you for the great library! I depend on it extensively in my project.

nonara added a commit to nonara/node-html-parser that referenced this issue Oct 3, 2021
@nonara nonara mentioned this issue Oct 3, 2021
@nonara
Copy link
Collaborator

nonara commented Oct 3, 2021

Happy to help! @taoqf is the library's author, but I'm sure he'll be glad to hear that it's working well for you!

I have this and several other fixes in place in the following PR, but I'll also follow-up in this thread when we have a release ready.

nonara added a commit to nonara/node-html-parser that referenced this issue Oct 3, 2021
@nonara nonara closed this as completed in 2b65583 Oct 10, 2021
@nonara
Copy link
Collaborator

nonara commented Oct 10, 2021

Corrected in v5

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

No branches or pull requests

2 participants