Renato Wagner Renato Wagner - 2 months ago 8
TypeScript Question

About typescript with es6. What I do, please?

I got this error:


[0] app/components/pessoas/detail/PessoaDetailComponent.ts(27,35): error TS2339: Property 'pessoa' does not exist on type '{}'.


Code:

export class PessoaDetailComponent
{
pessoa: any;

constructor(private _api: Api, private _params: RouteParams)
{
this._api.getPessoa(_params.get("id")).then(
(res) => {
//line 27// this.pessoa = res.pessoa;
},
(error) => {
console.error(error);
}
)
}
}

Answer

This is a type related issue. For whatever reason, typescript thinks res is of type {} and thus complains that pessoa doesn't exist on the type

use

(res: any) => {
  this.pessoa = res.pessoa;
},

or use the appropriate type if you know it.