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

Readonly Utility Type

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;
//   };
// }

Assignment

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.