loadcsv(file: File): string[] {
let csvRecordsArray: string[];
this.parse(file).then((p) => {
console.log(p);
csvRecordsArray = p as string[];
});
console.log('mydata', csvRecordsArray);
return csvRecordsArray;
}
console.log
inside the then
prints the data I need. Nothing wrong with the Promise
. However, since it does not block my second console.log
has undefined in csvRecordsArray
. So I read up on Promise
s and learnt that I need to await
. As soon as I type async
to make loadcsv
async
ts lint says:
Type 'string[]' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
Please help me get out of this tailspin.