七、TypeScript 之元组 - Tuple

与 声明数组类型 相似 数组

只不过在 数组 基础上更加细分化每一个元素tcp

示例:spa

let myTuple: [number, string, boolean] = [1, 'Poplar', true];

顺序不能够颠倒 长度不能够违规 是固定的code

若是你的数组没有知足元组要求:blog

let myTuple: [number, string, boolean, any] = [1, 'Poplar', true];

图片描述

报错意思就是 你的属性3个在类型中缺失,但在元组中设定是必须的;图片

若是你的元素没有知足数组的长度会怎么样呢:string

let myTuple: [number, string] = [1, 'Poplar', true];

图片描述

报错意思是 你的数组不能分配给元组,长度属性不兼容;it

相关文章
相关标签/搜索