// @flow
type Props = {
className?: string,
checked?: boolean,
[string]: string,
};
const Checkbox = ({
className = 'x',
checked = false,
...props,
}: Props) => {
console.log('render checkbox');
}
产生错误:
9: className = 'x',
^ Unexpected token =
10: checked = false,
^ Unexpected token =
12: }: Props) => {
^ Unexpected token =>
这是有效的javascript,但被流程拒绝。删除...props
会删除错误,但是我需要此功能。我是在做错什么,还是流程中的错误?
答案 0 :(得分:3)
这只是O型。多余的逗号
// @flow
type Props = {
className?: string,
checked?: boolean,
[string]: string,
};
const Checkbox = ({
className = 'x',
checked = false,
...props
}: Props) => {
console.log('render checkbox');
}
此外,您应该在类型顶部定义索引器,如下所示:
// @flow
type Props = {
[string]: string,
className?: string,
checked?: boolean
};