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

TS: waitForSelector should only resolve null when called with `hidden: true #3877

Closed
SimonSchick opened this issue Feb 1, 2019 · 3 comments

Comments

@SimonSchick
Copy link

SimonSchick commented Feb 1, 2019

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.12
  • Platform / OS version: MacOS
  • URLs (if applicable):
  • Node.js version: 11.5

What steps will reproduce the problem?

Please include code that reproduces the issue.

const el = await page.waitForSelector(some-selector);

console.log(el.getProperty('somewhat'))

What is the expected result?

No error

What happens instead?

error TS2531: Object is possibly 'null'.

Ideally an overload should be added specifically checking if hidden: true, otherwise we have to add annoying null assertions where none are needed.

@SimonSchick
Copy link
Author

Closing in favour of #3878

@jemunk
Copy link

jemunk commented Feb 12, 2024

What is the status of this? The year is 2024 and we still need to test if the result of waitForSelector returns null.
It could be so nice, that the hidden: true option, was refactored into its own method, like waitForHiddenSelector, and only let this one return null (or void).

@alamothe
Copy link

alamothe commented Sep 9, 2024

This can be resolved easily with overloading:

    waitForSelector<Selector extends string>(selector: Selector, options?: {
        visible?: boolean;
        hidden?: false;
        timeout?: number;
    }): Promise<ElementHandle<NodeFor<Selector>>>;
    waitForSelector<Selector extends string>(selector: Selector, options?: {
        visible?: boolean;
        hidden: true;
        timeout?: number;
    }): Promise<ElementHandle<NodeFor<Selector>> | null>;

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

No branches or pull requests

3 participants