元组
// 元组 const arr:[string, boolean, number] = ['123', false, 123] arr.push(456) // console.log(arr[3]) // 元组越界之后,虽然可以push,但是实际上访问不到,arr[3]报错 // arr.push({1:'1'}) // 会推断arr的类型是[string | boolean | number],传进去其他类型会报错 // 获取元组的类型 type first = typeof arr[0] // 获取元组的类型长度 type length = typeof arr['length']