Objects in TypeScript

Description

Objects are declared this way in TypeScript

let person = {
  name: 'marko',
  gender: 'male',
  age: 30
};
//The data type of the person variable is object.

Quick Note

  • If you declare a variable to be a particular data type, you can't change the data type and if the properties have been fixed to a particular data type, it can't be changed to another data type.
  • You can't add new properties to an object once it has been declared. You also can't add additional properties.
  • Once an object has been declared, it has to have same exact same data type and also the same properties. The values of the properties can be changed but it has to remain the same data type.