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
Puppeteer typings assume global DOM lib types #24419
Comments
I think, i am struggling with similar problem. did you get any solution?
|
For now, make stub interfaces for those interfaces in your own files: // See https://github.com/DefinitelyTyped/DefinitelyTyped/issues/24419
interface Element { }
interface Node { }
interface NodeListOf<TNode = Node> { } |
Is there a reason you don't just bring in the "dom" types in your tsconfig file? Puppeteer loads up a web browser, so I think it makes sense to use the "dom" types, even in Node. (assuming it doesn't cause other issues) |
Yeah, as you said there is no harm to define "dom" types in tsconfig. |
There is harm in defining the Even for apps that run in the context of the browser, it's not unreasonable to intentionally exclude |
Until this is resolved, |
Is there any progress to resolve this error? put |
It would be useful if Typescript (along with existing lib) also exported interfaces. So you could do something like import { Window } from 'typescript/lib/lib.dom.namespaced';
page.evaluate(() => {
(window as Window).alert('something');
}); |
Hi people, i'm facing the same problem with types definition, and Element is not exported from any Lib. To get apropriate intelisense with el methods, i changed my code with below example: From:
To this:
|
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the |
If anyone finds this issue in the future and wants an easy solution, you can use a triple-slash directive in the file you write your puppeteer code in. It's not perfect, but it allows you to say "I'm writing node code but for JUST this file tell the compiler to assume the DOM is also available". as @JoshuaKGoldberg noted, this is dangerous. It would be reasonable to make sure the puppeteer code is isolated in its own file. /// <reference lib="DOM" />
import puppeteer from "puppeteer";
// Do your puppeteer stuff.
export const runMyPuppeteerCode = async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
const someElement: Element = await page.evaluate(() => {
const aButton = document.querySelectorAll(".my-button");
... |
@types/xxxx
package and had problems.Definitions by:
inindex.d.ts
) so they can respond.Using Puppeteer in a Node project without the dom type
NodeListOf
gives type errors.@types/puppeteer
should provide an emptyinterface NodeListOf { }
shim for compilation runs that don't include the different"lib"
set. It should also compile without the dom lib types.Edit: double-checked; it's just
Element
,Node
, andNodeListOf
.The text was updated successfully, but these errors were encountered: