Deno seems to assume wrong return type (Puppeteer)
With the following code, I get an type error which I do not expect:
On the
shouldBeString
I receive the following type error:
Even though $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.
10 Replies
This isn't a Deno issue but just how TypeScript works
Undefined at least is very much correct:
null?.eval()
becomes undefined
.This seems to work indeed, thanks
To me it does look like TS should be properly determining the return value of the eval handler but I can't really say since I'm not on a computer.
Still a bit confused as to why TypeScript says $eval returns ElementHandle<any> | undefined
Beacuse you're using the
?.
operatorOptional chaining (?.) - JavaScript | MDN
The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called using this operator is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.
No I mean specifically the
ElementHandle<any>
part. Undefined makes senseAh, that should just be what puppeteer returns right?
but $eval should return : Promise<Awaited<ReturnType<Func>>>
Yes exactly
According to the docs it should be this