

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Single Source of Truth
incomplete
2: Partial Utility Type
incomplete
3: Required Utility Type
incomplete
4: Readonly Utility Type
incomplete
5: Record Utility Type
incomplete
6: Pick Utility Type
incomplete
7: Omit Utility Type
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
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.
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.
Our users' emails and phone numbers are usually optional but become required when it's time to make a purchase.
Complete the addBillingInfo function: