W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
const numbers = [1, 2, 3]; // 推断为 number[] 类型 numbers.push(4); // 没有错误 // 注释掉下面这行可以看到成功的赋值 numbers.push("2"); // 错误:类型 'string' 的参数不能赋给类型 'number' 的参数 console.log(numbers); let head: number = numbers[0]; // 没有错误 console.log(head);