代码如下:
报错内容:
Type ‘{ flexDirection: string; }’ is not assignable to type ‘Properties
’.
Types of property ‘flexDirection’ are incompatible.
Type ‘string’ is not assignable to type ‘FlexDirection | undefined’.ts(2322)
index.d.ts(1942, 9): The expected type comes from property ‘style’ which is declared here on type ‘DetailedHTMLProps’
解决方案 1:
const myStyle = {
flexDirection: "column",
} as React.CSSProperties;
解决方案 2:
class MyView extends Component {
render() {
return <div style={myStyle as React.CSSProperties}>my view</div>;
}
}