I'm creating a to-do application with firebase and typescript. I had this function that returns all the projects a current user has in it's list but when it came to adding information to it, it became hard.
Eventually I find a way but it still wasn't good enough, but certainly not clean and efficient enough. So i used chatbot to optimize it and the response was clean and understandable, but I can't seem to get why I'm getting the error:
Property 'map' does not exist on type 'QuerySnapshot'.
I have no clue what is wrong so maybe one of you can point it out..?
This is the function:
const returnProjects = async (id:string) => {
const array: string[] = [];
const list = document.querySelector<HTMLDivElement>('#projectList');
const projects = await getDocs(collection(db, 'projects'));
const projectsUsersPromise = projects.map(async (doc: any) => ({
users: await getCountFromServer(collection(db, `projects/${doc.id}/users`)),
data: doc.data(),
}));
const projectsUsers = await Promise.all(projectsUsersPromise);
projectsUsers.forEach((project: any) => {
const amountUsers = project.users.data().count;
const { name } = project.data();
const newElement = document.createElement('div');
if (list) list.appendChild(newElement).setAttribute('class', 'projectCard');
newElement.innerHTML = `
<h4>${name}</h4>
<div id='cardBottom'>
<div id='cardUsers'>
<img src='/src/img/user.svg' alt='Users' width='12vw' id='projectUsers'>
<span>${amountUsers}</span>
</div>
<img src='/src/img/info.svg' alt='Further information about this project' width='15vw' id='projectInfo'>
</div>
`;
});
};