//ts的核心原则之一 是对值所具有的结构进行类型检查 //接口: 是一种类型,是一种规范 (()=>{ /* 需求: 创建一个人的对象 需要对人的属性进行一定的约束 id 是number类型 只读 name 是string类型 必须有 age 是number类型 必须有 school 是string类型 可选项 */ //定义一个接口 interface IPerson{ readonly id: number name: string age: number school?: string } const person1: IPerson = { id: 1, name: 'xiaoming', age: 30 } // person1.id = 40 console.log(person1) /* 可选属性 ? 只读属性 readonly */ })()