1,元组同样是TypeScript中新增的一种数据类型,元组的功能总的来说:就是给定长度,类型的一个数组,它可以对数组中的每一项的类型进行精确定义,值的类型和长度必须和声明的保持一致
const userArr: [string,number,boolean] = ['张三','18', true]
2,可以通过类型别名的形式,可以将一个元组应用给多个对象使用
type Person = [string,number,boolean]
const userArra: Person = ['张三',18, true]
const userArrb: Person = ['李四',19, false]
3,枚举和元组可以配合使用
enum Gender {
man = '男',
woman = '女'
}
type Person = [string,number,Gender]
const userArra: Person = ['张三',18, Gender.man]
const userArrb: Person = ['李四',19, Gender.woman]