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.

RxJS core team member; front-end developer; mentor; speaker; open-source contributor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store