美文网首页
typescript 基础-- 接口

typescript 基础-- 接口

作者: ME88 | 来源:发表于2021-09-16 17:15 被阅读0次

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接口的规范

相关文章

网友评论

      本文标题:typescript 基础-- 接口

      本文链接:https://www.haomeiwen.com/subject/oezrgltx.html