Comment by coding123
4 years ago
I think it would be awesome for Typescript to introduce sync functions. So think of that as completely flipping the dialog on async/await to await by default:
sync function x() {
const taco = getTaco() // getTaco returns Promise<Taco>, but taco automatically resolves it in a sync function
// Similarly, you can tell it to not wait
const ptaco = nowait getTaco();
// ptaco is a Promise<Taco>
const taco2 = ptaco; // taco2 is a Taco because the ptaco symbol is treated like (await ptaco) without nowait
// Also, since ptaco has already "awaited", future
// access would be 0 delay as it's basically a resolved promise.
}
Of course, similar to an async function, sync functions would also return a promise.
Probably a dumb idea but I would use it personally.
I literally googled to see if this existed last week. Would also use!