effect icon indicating copy to clipboard operation
effect copied to clipboard

Requires DOM lib

Open samhh opened this issue 1 year ago • 2 comments

What version of Effect is running?

3.3.0

What steps can reproduce the bug?

{
  "compilerOptions": {
    "lib": ["esnext"] // missing "dom"
  }
}

What is the expected behavior?

The library should typecheck in server environments without DOM lib.

What do you see instead?

Various type errors pertaining to:

  • ReadableStream
  • QueuingStrategy
  • AddEventListenerOptions

Additional information

No response

samhh avatar Jun 11 '24 13:06 samhh

Effect depends on Web APIs that are commonly implemented by Node and the other most common runtimes such as edge runtimes, deno, bun. To have Effect typecheck you will need a set of global types that include those functionalities, note that those are also required at runtime so if your runtime doesn't have them you'll need to polyfill

mikearnaldi avatar Jun 12 '24 09:06 mikearnaldi

Here's a small repro: https://git.sr.ht/~samhh/effect-lib-dom-repro/

@types/node isn't enough to typecheck Effect, though Node as a platform does support Stream. Possibly this is an upstream issue as the package does include Stream types, in which case guidance would be welcome for projects that don't want to pollute their server environment with largely inapplicable DOM typings.

Having said that, AddEventListenerOptions is still an issue. Its inclusion in Stream.fromEventListener infects all consumers of Effect to require DOM lib. I believe RxJS manages to bypass this issue with its fromEvent.

samhh avatar Jun 12 '24 09:06 samhh