Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property '_body' does not exist on type 'Response'

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.

like image 476
georgej Avatar asked Sep 19 '16 13:09

georgej


People also ask

How do you fix property does not exist on type?

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!

Does not exist on type request?

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.

Does not exist on type TS2339?

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; };

Does not exist on type string?

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.


2 Answers

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.

like image 131
koninos Avatar answered Oct 05 '22 19:10

koninos


data.json(); 

will give you the json result: https://angular.io/docs/ts/latest/guide/server-communication.html

like image 35
Chris Avatar answered Oct 05 '22 17:10

Chris