I'm currently trying to grasp the concept of Observables in Angular 4. While watching a tutorial video on it, I attempted to create my first Observable but encountered an error in my IDE:
The generic type Observer requires 1 types argument(s)
Here's the snippet of my code:
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
import { Observer } from 'rxjs/Observer';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
const myObservable = Observable.create((observer: Observer) => {
setTimeout(() => {
observer.next('first package');
}, 2000);
});
}
}
I assume that I need to specify a generic type like this: Observable<any>
. However, in the tutorial I watched, the author didn't use any generics and it worked. Can someone please clarify why?