Objects in TypeScript

Below is an Object example in Type Script

//Object Declaration and Initialization
let demoObject = {
    empId : 332,
    empName : 'Tyson'
}
demoObject.empId = 400;
demoObject.empName = 'Justin'
console.log(JSON.stringify(demoObject));

//Object Declaration only
let dept: {
    depId: string|number,
    depName: string,
    depAdd: string
}

dept = { depId: 'IT', depName: 'Internet Technology', depAdd: 'Hello Address' };

Leave a Comment