

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 Readonly<T> utility creates a new type where all the top-level properties are readonly, preventing them from being reassigned after initialization.
interface UserProfile {
id: string;
name: string;
preferences: {
readonly theme: "light" | "dark";
notifications: boolean;
};
}
type ConstantUserProfile = Readonly<UserProfile>;
// this is the same as
// type ConstantUserProfile = {
// readonly id: string;
// readonly name: string;
// readonly preferences: {
// readonly theme: "light" | "dark";
// notifications: boolean;
// };
// }
Let's make sure the API config imported by our server can't be modified.
Complete the importConfig() function. It should return the given config object with all properties marked as readonly.