Read-only properties

Another typical situation is when you have properties to which you intend to assign values only once, just like we do with the ES6 const declaration keyword. You can mark the values as readonly:

interface StaticSettings {  readonly width: number,  readonly height: number}// There are no problems herelet settings: StaticSettings = {width: 1500, height: 750}// ...but this will throw an errorsettings.width = 1000// orsettings.height = 500

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.