/**
* object:对象类型,相当于any类型的一个子集
* js中对象:key to value,键值对
* ts中对象:key to type,键类型对
*
*/
let person = {
firstName: 'jack',
lastName: 'nick',
age: 18
}
let person1: object = {
firstName: 'jack',
lastName: 'nick',
age: 18
}
console.log(person.firstName); // jack
console.log(person1.name); // 调用没定义的属性会报错,如果object改为any就不会报错
TypeScript——TypeScript中的对象类型object
最新推荐文章于 2024-01-31 14:44:20 发布