React TypeScript 样式报错

代码如下:

报错内容:

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>;
  }
}
相关推荐
前端不太难9 分钟前
如何给 RN 项目设计「不会失控」的导航分层模型
前端·javascript·架构
用户40993225021213 分钟前
Vue3中v-show如何通过CSS修改display属性控制条件显示?与v-if的应用场景该如何区分?
前端·javascript·vue.js
不会聊天真君64720 分钟前
CSS3(Web前端开发笔记第二期)
前端·笔记·css3
discode25 分钟前
【开源项目技术分享】@host-navs 站导,一个简洁高效的网站链接导航工具站
前端
PieroPC29 分钟前
Nicegui 3.4.0 可以缩小组件之间的间距 label botton input textarea
前端
写代码的皮筏艇30 分钟前
数组 forEach
前端·javascript
running up1 小时前
Vite 全面解析:特性、对比、实践及最新演进
javascript·typescript
shoubepatien1 小时前
JavaWeb_Web基础
java·开发语言·前端·数据库·intellij-idea