问题
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