Deriving Types From Values 15 exercises
Problem

Extracting Return Types from Functions

Here we have a createUser function:


import { Equal, Expect } from "@total-typescript/helpers";
const createUser = (id: string) => {
return {
id,
name: "John Doe",
email: "example@email.com",
};
};

For the purposes of this exercise, assume that the createUser

Loading exercise

Transcript

00:00 We have a similar setup here to our previous exercise with parameters, but this time we're interested in the return type. We have a createUser function, which let's say we don't control at all, comes from a third-party library or a different source that we don't control. And we have a type called user here, which we're expecting to be exactly the same shape

00:18 as the return type of createUser. Your job is to try to figure out how we can type this user without needing to manually type it again. It's gonna be very similar to the parameters exercise, but this time using something called a return type, type helper.