TypeScript · Junior · Question 42 of 75

How do you type an async function that returns a 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>>.

Further reading

Problem with a question

TypeScript · Junior · question 42

Test yourself

Take the TypeScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz