Flow告诉我显式传入的字符串与null不兼容,并且它似乎与传入的爆炸对象有关。
我在react bootstrap库接口定义文件中有以下内容:
declare export type FormControlProps = {|
componentClass?: ?componentClass,
// componentClass is an enum of strings 'select' | 'div' etc
// There are other params here, too.
|}
以下是一个组件:
import { FormControl, type FormControlProps } from 'react-bootstrap';
type EnumSelectProps = {|
defaultText: string,
...FormControlProps,
|};
// and in the render method:
const { defaultText, ...other: FormControlProps } = this.props;
<FormControl
{...other}
componentClass="select"
value={this.state.value}
onChange={event => this.onChange(event.target.value)}
>
{ children }
</FormControl>
这似乎很好,对吧? ...other
的类型为FormControlProps
。但是,我得到了投诉:
v-----------
43: <FormControl
44: {...other}
45: componentClass="select"
...:
48: >
^ props of React element `FormControl`
45: componentClass="select"
^^^^^^^^ string. This type is incompatible with
463: componentClass?: ?componentClass,
^^^^^^^^^^^^^^^ null. See lib: flow-typed/npm/react-bootstrap_v0.x.x.js:463
是什么给出的?如果我将other
转换为any
(即...(other: any)
),则可行。另外,如果我只将componentClass
设为左侧可选componentClass?: componentClass
,则可行。 (但这不是正确的定义。)有没有更少的hacky方法来处理这个问题?谢谢!