I'm trying to consume a json with angular and it's giving me the error:
error TS2322: 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 tests:
export class Prueba {
public date: number;
public name: string;
public age: number;
}
I have found the solution to my own problem.
there was plenty of
<Prueba>
In the line of the map. where did i put before
<Prueba>.response.json()