Using Angular2 and typescript, I have JSON returned from a webApi and I need to get it into an array of a certain type. I can\'t figure out how to cast the json to the inte
You can do a type assertion to the interface you are expecting on the object created by JSON.parse.
this.http.get('http://localhost:4200/').subscribe((value: Response) => {
let hero = value.json();
});
However this will not result in any errors if the server sends you bad objects because of 2 reasons.
At compile time the transpiler does not know what the server will send.
At runtime all type information is erased since everything gets compiled to javascript.