I want to create a TypeScript interface that looks 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 I intend to use it in the following manner
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 issue arises when the Observable
type in the IUserService
is not recognized. If I switch to Promises and utilize Promise
as the type, then everything works fine, but my preference is to stick with Observable
.
I might be approaching this problem incorrectly. Open to suggestions for a solution or an alternative approach.
Appreciate any help offered