I want to define an array of products. I want to have for index 0 of that array five products, on index 1 I will have 6 products, etc. but I don't know how to declare it in typescript.
I have tried this:
public products: IProduct[];
public productsForRow: products[];
But it doesn't recognize products[];
My problem is that I don't know how to declare that the elements at the first dimension will be numbers, and the elements at the second dimension will be a IProduct
array. I don't think this will work:
public productsForRow: IProduct[][];
How can I do it?
You could define those types outside of the class as either type
or interface
like this:
interface IProduct {
whatever: string;
}
type products = IProduct[];
class YourClass {
public productsForRow: products[];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.