Open OliverJAsh opened 3 years ago
We can probably do something similar to this internally so that those types are available with DOM
being in lib
:
That would work but it would be a shame if we had to bring in all of the DOM
types. That would mean I could reference a global such as window
in my Node project, which doesn't really make sense.
Ideally TypeScript would provide the types for fetch
in a separate lib
so we could just bundle that.
We'd only be able to do it if it was in a fetch
-specific file, but even then - thinking about it more - I'm not sure we'd want to, as it'd always drag those types into the global namespace.
The only other thing I can think of is that we introduce our own interface that mirrors what is available in both DOM and Node impls. Then we don't have to worry about it. The only problem there is it becomes easier to mess up what we're developing. As maybe we get a property name wrong or something. :\
Suggestion
Here is a very simple Node project that attempts to use
fromFetch
: https://github.com/OliverJAsh/rxjs-fromfetch-nodeRunning
tsc
returns a bunch of errors. For example:If I understand correctly, this is because the RxJS typings are relying on globals provided by TypeScript's
DOM
lib
, but these globals will not exist for a Node project because theDOM
lib
is intentionally omitted:tsconfig.json
:To workaround this issue I had to create the globals myself:
This issue isn't immediately obvious, so perhaps we should document the steps to get it working. Or perhaps there is a way to rewrite the RxJS types so they never rely on the
DOM
lib
—after all, we shouldn't make assumptions about the environment the code will run in. What do you think?