So I'm getting a compiler error stating that token doesn't exist on type Object. This object is getting returned from the server with two objects. A token and a user object. I'm not sure how to define res in the code example below so that typescript is okay with this.
return this.http.post(api.url, params)
.map(res => {
if (res && res.token) {
localStorage.setItem('token', res.token);
localStorage.setItem('user', JSON.stringify(res.user));
return true;
}
return false;
});
Typescript is complaining the response does not have a property named token, Change it as,
return this.http.post(api.url, params)
.map((res:any) => {
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