My goal is to always include an error function when using rxjs's subscribe method. To achieve this, I am thinking of creating an interface by adding the following code snippet:
Observable.prototype.sub = Observable.prototype.subscribe;
By assigning a copy of subscribe to sub
, I aim to enforce the usage of TypeScript to ensure that sub
always requires specific functions to be provided.
var subscription = source.subscribe(
x => console.log('onNext: %s', x),
e => console.log('onError: %s', e),
() => console.log('onCompleted')
);
This approach will help me avoid forgetting to pass an error function (and potentially a completion function) when utilizing my custom sub
operator.
Best regards,
Sean