我想这样定义jsx:
<table style={{'--length': array.lenght}}>
<tbody>
<tr>{array}</tr>
</tbody>
</table>
我在 CSS 中使用 –length,我也有具有 –count 的单元格,它使用 CSS 伪选择器(使用计数器 hack)显示计数。
但打字稿抛出错误:
TS2326: Types of property 'style' are incompatible.
Type '{ '--length': number; }' is not assignable to type 'CSSProperties'.
Object literal may only specify known properties, and ''--length'' does not exist in type 'CSSProperties'.
是否可以更改样式属性的类型以接受 CSS 变量(自定义属性),或者有没有办法强制任何样式对象?
原文由 jcubic 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果你去 定义
CSSProperties
,你会看到:该链接提供了如何通过在
Properties
中增加csstype
的定义或将属性名称转换为any
来解决类型错误的示例。