ts 数组的类型

let fibonacci: number[] = [1, 1, 2, 3, 5];

//数组的项中不允许出现其他的类型:
// let fibonacci: number[] = [1, '1', 2, 3, 5]; 报错



//一个比较常见的做法是,用 any 表示数组中允许出现任意类型:
let list: any[] = ['xcatliu', 25, { website: 'http://xcatliu.com' }];
发布了180 篇原创文章 · 获赞 36 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/weixin_38404899/article/details/103719069