我正在学习TypeScript,所以请接受我的道歉问一个愚蠢的问题。数组解构不能与参数一起工作
下面的代码取自official docs,但它不起作用。它看起来像函数需要2个number
s的Tuple
代替Array
,但在另一方面,它应该拆解可根据文档演示阵...
let input = [1, 2];
function f([first, second]: [number, number]) {
console.log(first);
console.log(second);
}
f(input);
错误:
src/main.ts(6,3): error TS2345: Argument of type 'number[]' is not assignable to parameter of type '[number, number]'.
Property '0' is missing in type 'number[]'.