类型 'HttpEvent<name[]> 不可分配给类型 'name[]'

Type 'HttpEvent<name[]> is not assignable to type 'name[]'

这是我的代码:

export interface act {
  id: number;
  name: string;
}
public list!: act[];
getAll(token:any): void{
  this.http.get<act[]>('http://localhost:4200/test', token)
  .subscribe(
    (val) =>
      this.list = val
  );
}

我在 this.list = val 上收到以下错误:

Type 'HttpEvent < act[] >' is not assignable to type 'act[]'. Type 'HttpSentEvent' is missing the following properties from type 'act[]': length, pop, push, concat, and 16 more.

我尝试在 google 上搜索,在堆栈上阅读但没有成功。我发现了类似的问题,但有些没有解决,有些则不同。

希望你能帮助我,在此先感谢。

您正在尝试发送请求正文,但 GET 请求没有正文。 HttpClient.get() 的第二个参数不是正文,它是一组影响方法 returns.

的选项。

所以你应该使用 POST 或 PUT 而不是 GET。

并且您还应该避免使用 any 类型,以使您和编译器更容易理解所有内容(如果您使用正确定义的接口而不是any).