Nicholas Jamieson
1 min readAug 6, 2017

--

Maxim, the main reason for passing a PartialObserver is that’s all subscribe requires. subscribe has a few overloads:

subscribe(): Subscription;
subscribe(observer: PartialObserver<T>): Subscription;
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;

And I wanted to use the one that accepted just the one argument — the PartialObserver — as that would require only a single binding property.

The basic gist of it is that subscribe can be passed an observer object — that has the option of implementing next, error and complete methods — or it can be passed separate, optional next, error and complete handlers.

Interestingly, the PartialObserver interface is now somewhat redundant, as TypeScript 2.1 introduced the concept of mapped types — see the Mapped Types section in the documentation — and the Partial type, which could be used like this:

subscribe(observer: Partial<Observer<T>>): Subscription;

--

--

Nicholas Jamieson
Nicholas Jamieson

Written by Nicholas Jamieson

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

Responses (1)