W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
// 定义我们的元组 let ourTuple: [number, boolean, string]; // 正确初始化 ourTuple = [5, false, 'Coding God was here']; // 我们的元组对于索引 3 及以上的位置没有类型安全性 ourTuple.push('Something new and wrong'); // 改用我们的只读元组 const ourReadonlyTuple: readonly [number, boolean, string] = [5, true, 'The Real Coding God']; // 会抛出错误,因为它是只读的 ourReadonlyTuple.push('Coding God took a day off');