Angular 2 observed error - The “observer” parameter implicitly has “any” type.

I am learning Angular 2, and I am having problems with a service that will return an observable.

I see this error, but not sure why? I am trying to follow some tutorials that I found on the Internet ...

[ts] The parameter "observer" is implicitly of type "any".

My editor highlights the work of the "observer" at the beginning 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; } } 
+8
angular
source share
1 answer

This is not a mistake, but you can fix it like this:

 data = new Observable<string>((observer: Observer<string>) => { observer.next("123") }); 

Remember to import Observer though!

 import { Observer } from 'rxjs/Observer'; 
+8
source share

All Articles