The following custom RxJS operator (actually just a .filter equivalent for demonstration) is currently declared in an Angular 4.0.0-rc.2 component.
declare module 'rxjs/Observable' {
interface Observable<T> {
restrictToCommand<U>(f: (x: T) => U): Observable<U>;
}
}
Observable.prototype.restrictToCommand = function (cmd) {
return new Observable((observer) => {
const obs = {
next: (x) => {
if (x.command === cmd) {
observer.next(x);
}
},
error: (err) => observer.error(err),
complete: () => observer.complete()
};
return this.subscribe(obs);
});
};
This works fine. However, I would like to extract this declaration to a library that is responsible for external communication. The main import of this library is a singleton service.
How to properly export the prototype extension and the module declaration from within that library?
rxjs/add/operator/...and providerestrictToCommandOperator.jsin package root.