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

发布时间 2023-08-17 10:35:45作者: 空白格k

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, '其他' ]