TypeScript · Junior · Question 42 of 75
How do you type an async function that returns a user?
- ✓Correct answer:
async function getUser(): Promise<User> - 2
async function getUser(): User - 3
async function getUser(): Async<User>
Explanation
An async function always returns a promise, so the result type is Promise<User>. The annotation User causes an error. You can extract the promise's value type with Awaited<ReturnType<typeof getUser>>.