TS2322: Type 'Product[] | null' is not assignable to type 'Product[]' в чем проблема?

Интерфейс

export interface Product {
  id: number;
  name: string;
  description: string;
  price: number;
  imageURL: string;
}

И компонент

products: Product[] = [];

  ngOnInit() {
    this.dataService.sendGetRequest().pipe(takeUntil(this.destroy$)).subscribe((res: HttpResponse<Product[]>)=>{
      console.log(res);
      this.products = res.body; // Ошибка в этом месте
    })
  }

При компиляции выдает ошибку:

TS2322: Type 'Product[] | null' is not assignable to type 'Product[]'.   Type 'null' is not assignable to type 'Product[]'.

Как ее исправить?


Ответы (0 шт):