physicsboy
physicsboy

Reputation: 6316

Property does not exist on type 'Object' when it is what I really want - Angular2+

I am returning an object containing only one field, of which I would prefer to return rather than the whole object, yet I am being met with the erorr:

Property 'token' does not exist on type 'Object'

Is there any way I can get around this, or am I stuck returning res wholly?

UPDATE If I console.log() out what I get back, I am left with the following:

console.log(res):

Note: Tokens will be different on purpose due to how I have set up the code

Upvotes: 0

Views: 47

Answers (1)

Dhana Sekar
Dhana Sekar

Reputation: 641

You should specify the structure of the response object

Either use

this.http.post<{token:string}>(this.apiBaseUrl + '/auth', body)

or

this.http.post<any>(this.apiBaseUrl + '/auth', body)

Upvotes: 3

Related Questions