我无法找出输入这种类型的析构对象的语法
const { height: deviceHeight, width: deviceWidth } = Dimensions.get("window");
现在deviceHeight
和deviceWidth
被揭露,两者都应该是数字。
答案 0 :(得分:2)
我想你想要这个:
const { height: deviceHeight, width: deviceWidth }: { height: number, width: number } = Dimensions.get("window");
您可以通过将其插入以下内容来正确输入deviceHeight
和deviceWidth
:
// @flow
const { height: deviceHeight, width: deviceWidth }: { height: number, width: number } = { height: 1, width: 2 };
function logString(str: string) {
console.log(str);
}
logString(deviceHeight);
...给出了这个输出:
logString(deviceHeight);
^ Cannot call `logString` with `deviceHeight` bound to `str` because number [1] is incompatible with string [2].