Nicholas Jamieson
Jul 26, 2017 · 1 min read

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.

    Nicholas Jamieson

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade