Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript
https://effect.website
MIT License
6.14k stars 196 forks source link

Requires DOM lib #2979

Open samhh opened 2 weeks ago

samhh commented 2 weeks ago

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:

Additional information

No response

mikearnaldi commented 2 weeks ago

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

samhh commented 2 weeks ago

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. It's inclusion in Stream.fromEventListener infects all consumers of Effect to require DOM lib. I believe RxJS manages to bypass this issue with its fromEvent.