Since you are using the superset
typescript use the type Array (which is the Generic type) as follows, minimal example:
class Produto {
constructor(public id: number){
}
}
class Category {
constructor(public id: number){
}
}
const dataFindCategories = Array<Category>();
dataFindCategories.push(new Category(1));
dataFindCategories.push(new Category(2));
dataFindCategories.push(new Category(3));
let dataFindProducts = Array<Produto>();
dataFindCategories.forEach((category: Category) => {
dataFindProducts =
dataFindProducts.concat(category.id);
});
console.log(dataFindProducts);
and pay attention that when using .concat
the last change must be returned to the variable, because .concat
returns another array
.
Another way is with Spread Operator:
class Produto {
constructor(public id: number){
}
}
class Category {
constructor(public id: number){
}
}
const dataFindCategories = [];
dataFindCategories.push(new Category(1));
dataFindCategories.push(new Category(2));
dataFindCategories.push(new Category(3));
dataFindCategories.push(new Category(4));
let dataFindProducts = [];
dataFindCategories.forEach((category: Category) => {
dataFindProducts = [... dataFindProducts, category.id]; // Spread
});
console.log(dataFindProducts);
that return what:
productRepository.findByCategory
– novic