typescript 类型注解:是一种轻量级的为函数或者变量添加的约束 既 参数/变量类型,ts提供了静态的代码分析,可分析代码结构和提供的类型注解。 let person:string="字符串"
接口:是一种约束规则
interface IPerson{
first:string
last:string
}
function show(person:IPerson){
return person.first+person.last
}
定义一个对象
const person = {
first:‘你好’,
last:'啊'
}
console.log(show(person)); 执行函数show时里面的参数要符合IPerson接口的规范
网友评论