小编Lui*_*sio的帖子

Angular:“对象”类型可分配给很少的其他类型

我有一段在 Angular 5 中运行良好的代码,但我正在尝试更新到 Angular 8:

  this.awsService.getProfiles().subscribe(profiles => {
    this.profiles = profiles;
    if (this.profiles.length > 0 && this.profiles.indexOf(this.currentProfile) == -1) {
      this.currentProfile = this.profiles[0];
      localStorage.setItem('profile', this.currentProfile);
    }
  }, err => {
    this.profiles = [];
  })
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

ERROR in app/app.component.ts:85:9 - error TS2696: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
  Type 'Object' is missing the following properties from type 'string[]': length, pop, push, concat, and 26 more.

85         this.profiles …
Run Code Online (Sandbox Code Playgroud)

angular

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

angular ×1