const myPromise: Promise<string> = new Promise((resolve) => {
setTimeout(() => {
resolve("Hello, world!");
}, 1000);
});
async function promiseToString(promise: Promise<string>): Promise<string> {
try {
const result = await promise;
return result;
} catch (error) {
console.error("Failed to convert promise to string:", error);
return "";
}
}
promiseToString(myPromise)
.then((result) => {
console.log("Converted string:", result);
})
.catch((error) => {
console.error("Failed to convert promise to string:", error);
});