Beginner's TypeScript Tutorial (18 exercises)
Problem

Combining Types to Create New Types

Continuing with User and Post, we now have a getDefaultUserAndPosts function that has an unknown return type:

export const getDefaultUserAndPosts = (): unknown => {
  return {
    id: "1",
    firstName: "Matt",
    lastName: "Pocock",
    posts: [
      {
        id: "1",
        title: "How I eat so much cheese",
        body: "It's pretty edam difficult",
      },
    ],
  };
};

Challenge

Your challenge is to update the return type for the function so that it is both User and { posts: Post[] }.

Transcript

In this exercise I want you to find the return type for getDefaultUserAndPosts. We're typing it as unknown here, but what we really want it to be is user and an array of posts in a posts object here.

So we could do what we did last time and do the extends clause, but I want you to find a different solution here. Your only changes should be within this little area there. You should be able to find a way to get this to work and have this non-error down here.