The RxJS package includes an add/observable
directory (for static methods) and an add/operator
directory (for operators). When imported, the files in those directories patch the Observable
class (for static methods) and Observable.prototype
(for operators). Additionally, TypeScript declaration merging is used to declare the signatures for the patched methods.
You can see this in the source for add/observable/of
:
import { Observable } from '../../Observable';
import { of as staticOf } from '../../observable/of';Observable.of = staticOf;declare module '../../Observable' {
namespace Observable {
export let of: typeof staticOf;
}
}
And for observable/of
:
import { ArrayObservable } from './ArrayObservable';export const of = ArrayObservable.of;
The latter just exports a static method that can only be used via an explicit import, but the former adds the static method to Observable
so that it’s callable everywhere Observable
is imported.