With the following code, I get an type error which I do not expect:
const element: ElementHandle | null = await page.$('span.label-status');
const shouldBeString: string = await element?.$eval('a', (el): string => el.innerText);
On the shouldBeString I receive the following type error:
Type 'ElementHandle<any> | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
Even though $eval() returns any type: https://pptr.dev/api/puppeteer.page._eval
Anyone have an idea how to fix this?
This method runs document.querySelector within the page and passes the result as the first argument to the pageFunction.