typeScript学习-TS类型-其他特殊类型-可变元组

typeScript学习

可变元组:

let people: [string, number, string, string, string] = ["wangwu", 23, "地址", '13312341234', '备注']
// 当前三个数据固定格式,后面数据不确认格式时 用可变元组
// 可变元组
// let customers: [string, number, string, ...any[]] = ["wangwu", 23, "地址", '13312341234', '备注', 123, "其他"]


// 可变元组解构
let [custname, age, address, ...rest]: [string, number, string, ...any[]] = ["wangwu", 23, "地址", '13312341234', '备注', 123, "其他"]

console.log(custname, age, address) // wangwu 23 地址
console.log("rest:", rest) // rest: [ '13312341234', '备注', 123, '其他' ]

 

可变元组 tag(标签)

可变元组标签可以和解构名称一样或相似

与解构名称无关与后面数组有关

标签可以明确每个数据类型表达的意义

let [custname, age, address, ...rest]: [custname_: string, age_: number, address_: string, ...rest_: any[]] = ["wangwu", 23, "地址", '13312341234', '备注', 123, "其他"]

console.log(custname, age, address) // wangwu 23 地址
console.log("rest:", rest) // rest: [ '13312341234', '备注', 123, '其他' ]


export { }

 

posted on 2023-08-17 10:26  空白格k  阅读(45)  评论(0)    收藏  举报

导航