We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Required Utility Type

The Required<T> utility type does the opposite of Partial<T> - it forces all properties of a type to be required, even those that were originally optional.

Using Required<T>

Here's a practical example of using Required<T>:

interface BlogPost {
  title: string;
  content: string;
  tags?: string[];
  publishDate?: Date;
  author?: {
    id: string;
    name?: string;
  };
}

// All properties are now required
type MyRequiredBlogPost = Required<BlogPost>;

// MyRequiredBlogPost is equivalent to:
// {
//   title: string;
//   content: string;
//   tags: string[];
//   publishDate: Date;
//   author: {
//     id: string;
//     name?: string;
//   };
// }

As before, the Required<T> utility type is not recursive, it only affects the top-level properties.

Assignment

Our users' emails and phone numbers are usually optional but become required when it's time to make a purchase.

Complete the addBillingInfo function: