代码如下:
报错内容:
Type '{ flexDirection: string; }' is not assignable to type 'Properties<string | number, string & {}>'.
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<HTMLAttributes, HTMLDivElement>'
解决方案 1:
typescript
const myStyle = {
flexDirection: "column",
} as React.CSSProperties;
解决方案 2:
typescript
class MyView extends Component {
render() {
return <div style={myStyle as React.CSSProperties}>my view</div>;
}
}