Css 属性和 TextStyle 类型 [英] Css Properties and TextStyle Types

查看:63
本文介绍了Css 属性和 TextStyle 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 textStyle,它是一种 TextStyle(它来自 react-native 类型)或 React.CSSProperties.我想将此类型传递给 html span 元素的 style 属性.style 属性接受 React.CSSProperties 的类型.我的界面和跨度元素是:

I have a textStyle which is a type of TextStyle (it comes from react-native types) or React.CSSProperties. I want to pass this type to style attribute for html span element. style attribute accepts type of React.CSSProperties. My interface and span element is:

export interface IBaseTextStyleType {
    textStyle:  React.CSSProperties | TextStyle
}

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

我在跨度样式中遇到此错误:

I got this error in style of 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'.

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

How can I rid of this error ?

推荐答案

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

You try to define type of style.textStyle like this:

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

这篇关于Css 属性和 TextStyle 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆