I am learning Angular 2 and am having trouble with a service that is going to return an observable.
I am seeing this error but am not sure why? I'm trying to follow some tutorials I found on the web...
[ts] Parameter 'observer' implicitly has an 'any' type.
My editor highlights the 'observer' work at the start of the lambda.
I am using Angular "2.0.0-rc.2"
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class LocationService {
constructor() { }
getLocation(): Observable<string> {
let data: Observable<string>;
data = new Observable<string>(observer => {
observer.next("123")
});
return data;
}
}
This is not an error, but you can fix it like so:
data = new Observable<string>((observer: Observer<string>) => {
observer.next("123")
});
Don't forget to import Observer
, though!
import { Observer } from 'rxjs/Observer';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With