Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 observable error - 'Parameter 'observer' implicitly has an 'any' type.'

Tags:

angular

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;
    }
}
like image 733
Ben Cameron Avatar asked Jun 23 '16 12:06

Ben Cameron


1 Answers

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';
like image 158
rinukkusu Avatar answered Sep 28 '22 10:09

rinukkusu