我今天面临一个奇怪的问题,
我有一个用流键入的React组件(对于SEO来说是a.k.a flowtype),由于某种原因它在这里显示了输入错误,这里是简化的代码。
type Props = {
someObject: { [string]: string },
};
class ComponentOne extends React.Component<Props> {
render() {
return (
// No idea why there's a linting error, seems like a bug
<div className={this.props.someObject.someKey} />
);
}
}
const WithEnhancements = enhance(magic)(ComponentOne);
export default () => (
<RenderPropComponent>
{({ someProp }) => {
return <WithEnhancements someProp={someProp} />;
}}
</RenderPropComponent>
);
错误是'someObject.someKey' is missing in props validation
。我正在撞墙,不知道是什么原因造成的,同样的打字对于其他组件中使用的相同数据结构工作得非常好,可能是eslint
对多组件文件不满意的错误吗?
更新:看起来像一个eslint bug,由于某种原因,当prop被这样解构然后使用someObject.someKey
时它可以工作:
const { someObject } = this.props;
据here报道,它目前是一种猫屎虫。它可以通过frontendgirl提到的道具解构来解决,虽然这可能看起来不像干净的代码,但你只需要为你有一个地图对象的组件(一个带有索引器属性的组件,{ [string]: string }
)。