I would like to make a TypeScript interface like this:
declare namespace UserService {
interface IUserService {
// Error: "Observable" can't be found
getUsers(): Observable<Array<UserService.IUser>>;
}
interface IUser {
Id: number;
FirstName: string;
LastName: string;
}
}
...and then use it like this
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map'
@Injectable()
export class UserService implements UserService.IUserService {
private usersUrl = 'http://localhost:12345/api/users';
constructor(private http: Http) {}
public getUsers(): Observable<Array<UserService.IUser>> {
return this.http.get(this.usersUrl).map(response => response.json() as Array<UserService.IUser>);
}
}
The problem is that the Observable type in the IUserService isn't found. If I use Promises and use Promise as the type then the Promise type is found but I want to use Observable.
It is possible I'm thinking about this wrong. I will accept a solution or an alternative.
Thank you
import { Observable } from 'rxjs/Observable';before thedeclare namespace UserService {?