首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Css属性和TextStyle类型

Css属性和TextStyle类型
EN

Stack Overflow用户
提问于 2021-01-28 07:22:44
回答 1查看 484关注 0票数 0

我有一个textStyle,它是TextStyle的一种类型(它来自于react原生类型)或React.CSSProperties。我希望将此类型传递给html span元素的样式属性。样式属性接受React.CSSProperties类型。我的接口和span元素是:

代码语言:javascript
复制
export interface IBaseTextStyleType {
    textStyle:  React.CSSProperties | TextStyle
}

<span style={style.textStyle}>
    {this.props.children || this.props.text}
</span>

我在span的风格上出现了这个错误:

代码语言:javascript
复制
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'.

我怎样才能消除这个错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-29 09:29:29

您尝试像这样定义style.textStyle的类型:

代码语言:javascript
复制
<span style={style.textStyle as React.CSSProperties}>
    {this.props.children || this.props.text}
</span>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65932634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档