I have been given a code with three essential parts that cannot be altered:
1. First, there is a call to the getData function, followed by printing the output.
getData().then(console.log);
2. The function signature is as follows:
async getData(): Promise<string[]>
3. There is also the getDataFromUrl function:
function getDataFromUrl(url: string, callback: any) {
fetch(URL)
.then((content: any) => content.json())
.then((data) => callback(data));
}
Below is my implementation for the getData function:
async getData(): Promise<string[]> {
return await new Promise<any>(function(resolve, reject) {
resolve(getDataFromUrl(myUrl, ((data: string[]): string[]=> {
return data
})))
});
}
The issue I am facing is that the code after the fetch function is executed after:
getData().then(console.log);
Therefore, console.log ends up printing: undefined
What modifications do I need to make in the getData function to resolve this?
Thank you