DenoDDeno
Powered by
Max van der VeldeM
Denoβ€’3y agoβ€’
13 replies
Max van der Velde

Deno seems to assume wrong return type (Puppeteer)

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);
const element: ElementHandle | null = await page.$('span.label-status');
const shouldBeString: string = await element?.$eval('a', (el): string => el.innerText);


On the
shouldBeString
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'.
Type 'ElementHandle<any> | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.


Even though
$eval()
$eval()
returns any type: https://pptr.dev/api/puppeteer.page._eval

Anyone have an idea how to fix this?
Page.$eval() method | Puppeteer
This method runs document.querySelector within the page and passes the result as the first argument to the pageFunction.
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Deno + Puppeteer causing compiler issues.
TangJieHaoTTangJieHao / help
2y ago
Please help to run puppeteer with deno?
BhauminBBhaumin / help
2y ago
Deno type enforcement
MqxMMqx / help
3y ago
deno runtime extensions seems to be not working
AV6AAV6 / help
3y ago