can anyone help me to \"translate\" this example in Typescript with async/await
console.log(\"start\")
var citiesRef = db.collection(\'cities\');
var allCi
Without knowing the types, I assumed base on their usage that they conform to the following interface:
var db: {
collection(name: 'cities'): {
get(): Promise>
}
};
Given that declaration, an async/await version of the code would be
async function foo() {
console.log("start")
var citiesRef = db.collection('cities');
try {
var allCitiesSnapShot = await citiesRef.get();
allCitiesSnapShot.forEach(doc => {
console.log(doc.id, '=>', doc.data().name);
});
console.log("end")
}
catch (err) {
console.log('Error getting documents', err);
}
}