Avatar ·

How to properly reject a promise when using async/await in TypeScript?

Hello everyone! I recently started learning async/await in TypeScript and encountered a problem. I have a function that should perform an asynchronous operation, but under certain conditions I need to return an error (reject). The problem is that I don't understand how to properly "reject" a promise when using async/await syntax. Here's an example of my code: ```typescript async function fetchUserData(userId: string): Promise { // Want to reject the promise if userId is empty if (!userId) { // How to properly reject here? } const response = await fetch(`/api/users/${userId}`); return response.json(); } ``` I know that in classic Promise you can call reject(), but in an async function return automatically completes the promise with resolve. I tried throw