My function is not returning anything when i want it to return an array based on the type argument. I tried to go with generic type but i couldn't assign my type Array to a t Array...
getNourritureFromDb(type){
this.nourritureCollection = this.cantineappdb
.collection("Inventaire")
.doc("Nourriture")
.collection(type);
switch (type) {
case "Plats": {
this.nourritureCollection.ref.get().then(data => {
let platArray : Plat[] = [];
data.docs.forEach(doc => {
let plat = new Plat("", 0, false, 0, "", "", [""], false);
plat.name = doc.data().nourritureJson.name;
plat.price = doc.data().nourritureJson.price;
plat.ingredients = doc.data().nourritureJson.ingredients;
plat.type = doc.data().nourritureJson.type;
plat.availableQuantity = doc.data().nourritureJson.availableQuantity;
plat.isAvailableOffMenu = doc.data().nourritureJson.isAvailableOffMenu;
plat.imgUrl = doc.data().nourritureJson.imgUrl;
plat.temp = doc.data().nourritureJson.temp;
platArray.push(plat);
});
return platArray;
});
break;
}
case "Entrees": {
this.nourritureCollection.ref.get().then(data => {
let entreeArray : Entree[] = [];
data.docs.forEach(doc => {
...
});
return entreeArray
});
break;
}
case "Snacks": {
this.nourritureCollection.ref.get().then(data => {
let snackArray : Snack[] = [];
data.docs.forEach(doc => {
...
return snackArray
});
break;
}
case "Boissons": {
this.nourritureCollection.ref.get().then(data => {
let boissonArray : Boisson[] = [];
data.docs.forEach(doc => {
...
return boissonArray
});
break;
}
case "Desserts": {
this.nourritureCollection.ref.get().then(data => {
...
return dessertArray
});
break;
}
default : {
let emptyArray: any[] = [];
console.log("Aucun type sélectionné");
return emptyArray
}
}
}
I want my function to return the kind of array that was called in the type argument. My goal would be that i could call something like let plat[] = getNourritureFromDb("Plats");