-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Labels
Description
the problem
i want to be able to use the dom types that playwright uses without incorrectly making globals like window available in the nodejs runtime.
import { chromium } from 'playwright';
(async () => {
window // undefined in nodejs
await chromium.launch()
})()the two options
1. dom types disabled
if i disable dom types by setting the lib property in tsconfig.json, i correctly get a compile error:
{
"compilerOptions": {
"lib": ["es2021"]
}
}asdf.ts:4:5 - error TS2304: Cannot find name 'window'.
4 window
~~~~~~
but i also get hundreds of other compile errors because playwright relies on these globally defined dom types:
node_modules/playwright-core/types/structs.d.ts:43:40 - error TS2304: Cannot find name 'Node'.
43 export type SmartHandle<T> = T extends Node ? ElementHandle<T> : JSHandle<T>;
~~~~
node_modules/playwright-core/types/structs.d.ts:44:49 - error TS2304: Cannot find name 'HTMLElementTagNameMap'.
44 export type ElementHandleForTag<K extends keyof HTMLElementTagNameMap> = ElementHandle<HTMLElementTagNameMap[K]>;
~~~~~~~~~~~~~~~~~~~~~
node_modules/playwright-core/types/structs.d.ts:44:88 - error TS2304: Cannot find name 'HTMLElementTagNameMap'.
44 export type ElementHandleForTag<K extends keyof HTMLElementTagNameMap> = ElementHandle<HTMLElementTagNameMap[K]>;
Found 132 errors in 3 files.
2. dom types enabled
{
"compilerOptions": {
"lib": ["es2021", "dom"]
}
}when enabling the dom types, there are no compile errors, even though the window object does not exist at runtime in nodejs
possible solution
perhaps a version of the dom types that are not defined globally? maybe this is a broader issue and could be raised on typescript?
DetachHead