In this example, I am going to create an object in TypeScript and then add up the two properties within that object.
First of all, let us create the object in TypeScript.
let numberObj : any = {
number1 : 1,
number2 : 2
}
The above object belongs to the loose type with two property values.
Next, let us create the function to add up the two properties of that object.
function adding(obj : any) : number {
return obj.number1 + obj.number2
}
The above function will return the summation of two numbers.
At last, let us call the function and then print its outcome.
console.log(adding(numberObj)) /* 3 */
TypeScript object is the most important element in TypeScript, you can create various methods and properties within that object for further use in the future.