0
我有这样的代码:场景,流量工程解构函数参数,但不能用于非解构后的参数
function myFunction({x}: {x?: number} = {}) {
console.log(x);
return 'foo';
}
function wrapper({x}: {x: number}) {
return myFunction({x});
}
function myFunction2({x}: {x?: number} = {}) {
console.log(x);
return 'foo';
}
function wrapper2(args: {x: number}) {
return myFunction2(args);
}
myFunction
和wrapper
做同样的事情myFunction2
和wrapper2
,对不对?但流动认为有后者复制(live demo)错误:
16: return myFunction2(args);
^object type. This type is incompatible with the expected param type of
10: function myFunction2({x}: {x?: number} = {}) {
^object type
这是一个错误,还是我失去了一些东西,这两个例子是不等价的?