错误TS2339:"对象"类型上不存在属性"电子邮件"

12 angular

我正在使用角度5,我得到一个错误,继承人的代码:

signIn(provider) {
    this._auth.login(provider).subscribe(
      (data) => {
        console.log(data);
        this.hideForm = false;

        this.emaill = data.email;
        this.nom = data.last_name;
        this.prenom = data.first_name;
        this.profileImage = data.image;
    })
}
Run Code Online (Sandbox Code Playgroud)

错误是:

src/app/authentification/authentification.component.ts(34,28):错误TS2339:"对象"类型上不存在属性"电子邮件".src/app/authentification/authentification.component.ts(35,25):error TS2339:类型'Object'上不存在属性'last_name'.src/app/authentification/authentification.component.ts(36,28):error TS2339:类型'Object'上不存在属性'first_name'.src/app/authentification/authentification.component.ts(37,34):错误TS2339:属性'对象'上不存在属性'图像'.

Nut*_*tan 51

替换(data)(data : any)第3行.

  • 给新人的提示:添加 `:any` 时,请确保将整个内容括在括号中。例如,当您想要将“data”转换为any时,请使用“(data:any)”。另一个例子,如果你想将“result”转换为“any”,则为:“(result:any)”。确保使用“()”,否则您将面临 TSLint 错误。希望这对某人有帮助。 (3认同)
  • 这不是一个好的解决方案,指定“any”只会关闭类型检查,从而违背了 Typescript 的全部目的。 (2认同)