Dhananjay Patel Logo
  1. Home
  2. / Blog
  3. / Typescript Api
  4. / Lessons
  5. / 3

Readonly

  • Readonly is used to prevent properties from being modified after they are initialized.
  • This is enforced at compile time, offering additional safety in your code.
interface Config {
readonly endpoint: string;
readonly apiKey: string;
}
const config: Config = {
endpoint: 'https://api.example.com',
apiKey: 'abcdef123456',
};
// config.apiKey = 'newkey'; // Error: Cannot assign to 'apiKey' because it is a read-only property.