I am trying to consume a json with angular and it is giving me the error:
TS2322 error: Type 'Observable < {} | Test > ' is not assignable to type 'Observable'. Type '{} | Test 'is not assignable to type' Test '. Type '{}' is not assignable to type 'Test'. Property 'date' is missing in type '{}'.
My service:
@Injectable()
export class MyService {
constructor(private http: Http) { }
private urlTo = 'http://url.com/json/';
getData(): Observable<Prueba> {
return this.http.get(this.urlTo)
.map((response: Response) => <Prueba>response.json())
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
The class tries:
export class Prueba {
public date: number;
public name: string;
public age: number;
}