Flow typing of styled component props doesn't work

大憨熊 提交于 2019-12-11 08:59:35

问题


I have this styled component:

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;'}
`;

And call it this way:

<IconWrapper iconAlign="left">

but Flow gives me the following error:

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)

回答1:


Looks like custom properties on a builtin component is not currently supported for a few reasons but namely Flow's still developing support for tagged template literals. The discussion at https://github.com/flow-typed/flow-typed/pull/2933 is quite useful for understanding why your example won't work currently and the steps being taken to make it possible.



来源:https://stackoverflow.com/questions/55689609/flow-typing-of-styled-component-props-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!