【发布时间】:2019-09-05 11:03:34
【问题描述】:
我有这个样式的组件:
type Props = {
iconAlign: string,
};
const IconWrapper: ComponentType<Props> = styled.View`
margin: 10px 10px 0px 10px;
position: absolute;
${({ iconAlign }: Props) =>
iconAlign === 'left' ? 'left: -35px;' : 'right: -35px;'}
`;
这样称呼它:
<IconWrapper iconAlign="left">
但是 Flow 给了我以下错误:
Cannot call styled.View because property iconAlign is missing in object type [1] in the first argument of array element.
"flow-bin": "0.96.0",
"styled-components": "^4.2.0",
libdef: styled-components_v4.x.x (satisfies styled-components@4.2.0)
【问题讨论】:
-
当你调用
IconWrapper时,你不应该传递propiconAlign并且它是强制性的?你可以写ComponentType<{ iconAlign?: string }>,所以propiconAlign可以是未定义的,或者为iconAlign设置一个defaultProps。 -
@Deve 我将 iconAlign 传递给我的组件。
标签: reactjs types flowtype styled-components