Having some issues using rxjs Observable.concat function in typescript. Encountering an error "Cannot read property 'apply' of undefined"
The problem appears to be limited to typescript and may be related to rxjs version 5 concat. The code seems functional with rxjs V4.
Below is a simplified example of the code showcasing the issue...
/*jshint esnext: true */
console.clear();
console.log('started');
class test{
observableArray: Observable<any>[]=[];
constructor(){
this.observableArray.push(Rx.Observable.return("Line 1"));
this.observableArray.push(Rx.Observable.return(56));
this.observableArray.push(Rx.Observable.create((observer)=>{
setTimeout(()=>{
try{
observer.onNext("Waited for");
observer.onCompleted();
}
catch(err){
observer.onError(err);
}
},3000);
}));
}
run(){
// ... indeterminate number of observables pushed into array.
// The issue arises below
var source = Rx.Observable.concat(...this.observableArray);
// transpiles into js as: source = Observable_1.Observable.concat.apply(Observable_1.Observable, this.observableArray);
// Error received in chrome debugger: Cannot read property 'apply' of undefined
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.error('Error: ' + err);
},
function () {
console.log('Completed');
});
}
}
}
Check out the live demo on jsbin: https://jsbin.com/naxeba/edit?html,js,console,output