I managed to find a workaround, since rxjs does not build with type definitions for its UMD bundle.
First of all, this only works for TS >= 3.5, because you have to switch on allowUmdGlobalAccess, or else it will give you this error:
TS2686: 'rxjs' refers to a UMD global, but the current file is a
module. Consider adding an import instead.
By inspecting the end of the file node_modules/rxjs/dist/bundles/rxjs.umd.js
, you can find that operators, testing, ajax, webSocket and fetch are like subnamespaces, and everything else is directly under the global rxjs
:
...
var operators = _operators;
var testing = _testing;
var ajax$1 = _ajax;
var webSocket$1 = _webSocket;
var fetch$1 = _fetch;
exports.operators = operators;
exports.testing = testing;
exports.ajax = ajax$1;
exports.webSocket = webSocket$1;
exports.fetch = fetch$1;
exports.Observable = Observable;
exports.ConnectableObservable = ConnectableObservable;
exports.GroupedObservable = GroupedObservable;
exports.observable = observable;
...
So all you have to do is create a .d.ts file like this:
export * from 'rxjs'
export * as operators from 'rxjs/operators'
export * as testing from 'rxjs/testing'
export * as ajax from 'rxjs/ajax'
export * as webSocket from 'rxjs/webSocket'
export * as fetch from 'rxjs/fetch'
export as namespace rxjs
And now you can use the global rxjs
in any of you ts files:
const { interval } = rxjs
const { filter } = rxjs.operators
interval(500).pipe(
filter(t => t % 2 === 0)
).subscribe(t => console.log(t))