Skip to content
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

Types and execution context (evaluation functions): suggested patterns #46

Open
jsejcksn opened this issue Feb 1, 2022 · 0 comments
Open

Comments

@jsejcksn
Copy link

jsejcksn commented Feb 1, 2022

When writing evaluation functions to be executed in a puppeteer page (e.g. page.evaluate(fn)), it is desirable to have access to the native TS window and DOM types within those functions.

The two environments (Deno and browser) share quite a bit of API overlap, but also have some exclusive parts (e.g. globalThis.Deno in Deno vs window.document in browser, etc.). One simple approach is to include all type libs in a Deno config, like this:

deno.json:

{
  "compilerOptions": {
    "lib": [
      "deno.window",
      "dom",
      "dom.iterable"
    ]
  }
}

However — because runtime errors will occur when using browser-exclusive APIs in Deno (or Deno-exclusive APIs in browser evaluation functions) — the above approach prevents the compiler from catching these environment-mismatch errors and emitting related diagnostics.

To me, at least, it is desirable to maintain type safety in these independent execution contexts (Deno vs browser). Are there any established patterns for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant