我有一个textStyle,它是TextStyle的一种类型(它来自于react原生类型)或React.CSSProperties。我希望将此类型传递给html span元素的样式属性。样式属性接受React.CSSProperties类型。我的接口和span元素是:
export interface IBaseTextStyleType {
textStyle: React.CSSProperties | TextStyle
}
<span style={style.textStyle}>
{this.props.children || this.props.text}
</span>我在span的风格上出现了这个错误:
Type 'CSSProperties | TextStyle' is not assignable to type 'CSSProperties'.
Type 'TextStyle' is not assignable to type 'CSSProperties'.
Types of property 'aspectRatio' are incompatible.
Type 'number' is not assignable to type 'AspectRatio'.我怎样才能消除这个错误?
发布于 2021-01-29 09:29:29
您尝试像这样定义style.textStyle的类型:
<span style={style.textStyle as React.CSSProperties}>
{this.props.children || this.props.text}
</span>https://stackoverflow.com/questions/65932634
复制相似问题