【发布时间】:2017-12-03 08:33:53
【问题描述】:
我有一个非常简单的函数,我正在尝试使用 Flow 进行验证:
// @flow
type Props = {
width: string | number,
};
function fun({
width = '30em',
}: Props) {
return width;
}
问题是我得到了这个错误:
8: width = '30em',
^ number. This type is incompatible with
8: width = '30em',
^ string
8: width = '30em',
^ string. This type is incompatible with
8: width = '30em',
^ number
8: width = '30em',
^ string. This type is incompatible with
8: width = '30em',
^ number
我想知道我做错了什么......这种其他方式工作正常:
// @flow
type Props = {
width: string | number,
};
function fun(props: Props) {
const {
width = '30em',
} = props;
return width;
}
函数参数中的这种语法似乎得到了支持,因为:
// @flow
type Props = {
width: string,
};
function fun({ width = '30em' }: Props) {
return width;
}
这很好用。
想法?
【问题讨论】:
-
如果这是问题所在,即使在我的第二个示例中它也应该抛出错误。此外,它应该引发语法错误。此外,它适用于单一类型。
-
这绝对看起来像一个错误。如果您认为它与 Jared 链接的不一样,请登录另一个。
-
我已经做到了here
标签: javascript flowtype