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>;
  }
}
相关推荐
NEXT065 小时前
前端算法:从 O(n²) 到 O(n),列表转树的极致优化
前端·数据结构·算法
剪刀石头布啊6 小时前
生成随机数,Math.random的使用
前端
剪刀石头布啊6 小时前
css外边距重叠问题
前端
剪刀石头布啊6 小时前
chrome单页签内存分配上限问题,怎么解决
前端
剪刀石头布啊6 小时前
css实现一个宽高固定百分比的布局的一个方式
前端
剪刀石头布啊6 小时前
js数组之快速组、慢数组、密集数组、稀松数组
前端
mango_mangojuice6 小时前
Linux学习笔记(make/Makefile)1.23
java·linux·前端·笔记·学习
Days20506 小时前
简单处理接口返回400条数据本地数据分页加载
前端
Novlan17 小时前
@tdesign/uniapp 图标瘦身
前端
ManThink Technology7 小时前
如何使用EBHelper 简化EdgeBus的代码编写?
java·前端·网络