I am using Angular 2 and getting this error when using an observable Property '_body' does not exist on type 'Response'
. The code is below
this.securitiesService.getMarketMovers() .subscribe(data => { console.log(JSON.parse(data._body)) });
The getMarketMovers function is simply this:
getMarketMovers() { return this._http.get('...url address...') }
I have tried to set data
to type any
but that isn't working for me. The code works and there is definitely a _body
property on data but it still throws there error and I cant build with this error.
Any help is greatly appreciated.
The "Property does not exist on type '{}'" error occurs when we try to access or set a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names. Copied!
The "Property does not exist on type Request" error occurs when we access a property that does not exist in the Request interface. To solve the error, extend the Request interface in a . d. ts file adding the property you intend to access on the request object.
To fix the error "TS2339: Property 'x' does not exist on type 'Y'" with TypeScript, we should make sure the properties are listed in the interface that's set as the type of the object. interface Images { main: string; [key: string]: string; } const getMainImageUrl = (images: Images): string => { return images. main; };
The "Property does not exist on type String" error occurs when we try to access a property that does not exist on the string type. To solve the error, use an object instead of a string, or make sure you're accessing a valid built-in method on the string.
UPDATE
Another way, is to explicitly tell TypeScript that we’re not interested in doing strict type checking.
(<any>data)._body
ORIGINAL
This data["_body"]
should work.
data.json();
will give you the json result: https://angular.io/docs/ts/latest/guide/server-communication.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With