1、对象类型
2、示例
const emp1 = {
name : {
first : '四',
last : '张'
},
gender : 'male' as 'male' | 'femal'| 'other' | 'unknown', //指定初始值为male
salary:8000,
bouns:undefined as (number | undefined),
performance:3.5,
badges: ['优秀员工','迟到王'],
}
if(!emp1.bouns){
emp1.bouns = emp1.salary * emp1.performance
}
emp1.gender = 'other'
const s:string = JSON.stringify(emp1)
console.log('JSON:',s)
//"JSON:", "{"name":{"first":"四","last":"张"},"gender":"other","salary":8000,"bouns":28000,"performance":3.5,"badges":["优秀员工","迟到王"]}"
const emp2 = JSON.parse(s) //生成为新的对象
// 两个对象并不相同
console.log('emp1 === emp2?',emp1 === emp2) //false