I hava an interface called Products
export interface Products{
category: string;
imageUrl: string;
price: number;
title: string;
}
I have a variable in my component of type products array
products: Products[];
I am trying to map my response from my service to the products variable, but I get this error Type
'{}[]' is not assignable to type 'Products[]'
and I don't know what i'm doing wrong
this.subscription = this.productService
.getAll()
.subscribe(
products =>
(this.products = products.map(p => ({ ...(p.payload.val() as {}) }))),
)
pdoes? (Within the map function)payloadhave a method? Most payloads I've seen are plain data objects.prefer to products?as {}in there; do you mean to doas Productor leave off theasclause if it's type inferable? You're basically telling the compiler to make an{}[].