美文网首页
typescript interface

typescript interface

作者: Aurora_卷 | 来源:发表于2021-04-26 20:23 被阅读0次

1.声明接口  大写驼峰

interface TestProps {

    _id:string,

    name:string

}

2创建数组对象,每一项都是TestProps类型

const testData:TestProps[]=[{_id:'1',name:'a'},{_id:'12',name:'ab'},{_id:'123',name:'abc'},]

3.可索引的建 用方括号

创建对象数据,键值类型是string

const testData2:{[key:string]:TestProps}= 

  '2':{_id:'1',name:'a'},

 '12':{_id:'1',name:'a'},

}

相关文章

网友评论

      本文标题:typescript interface

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