Adir Zoari Adir Zoari - 1 month ago 74
TypeScript Question

Error TS4053: Return type of public method from exported class has or is using name ‘Observable’

i'm trying to build app with ionic 2 & angular 2,
i get this error while i try to run my app.
i build another project to check and the same problem,
i really confused on this problem.

error in photo

this is my service code

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Storage} from '@ionic/storage';
import {NavController} from "ionic-angular";


/*
Generated class for the MyService provider.

See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class MyService {
public local :Storage;
public getsession : any;
constructor(private http: Http, private navCtrl : NavController) {
this.local = new Storage();
console.log("my-service page")
}

postLogin(data){
let link = "http://adirzoari.16mb.com/login.php";
return this.http.post(link,data)
.map(res => res.json())
}

checkToken(){
return this.getsession =this.local.get('token');
}

}

Answer

I only add this as an answer so it could help other SO users facing the same issue.

Just like @sudheer-kb mentioned, in order to solve that issue, you need to explicitly import the Observable class:

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Observable } from "rxjs/Observable"; // <- add this import
import {NavController} from "ionic-angular";
Comments