Typescript Css属性和文本样式类型

Typescript Css属性和文本样式类型,typescript,react-native,Typescript,React Native,我有一个textStyle,它是textStyle的一种类型(它来自react原生类型)或react.CSSProperties。我想将此类型传递给html span元素的style属性。style属性接受React.CSSProperties的类型。我的界面和跨度元素是: export interface IBaseTextStyleType { textStyle: React.CSSProperties | TextStyle } <span style={style.t

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

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

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

如何消除此错误?

您尝试定义
style.textStyle的类型,如下所示:

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

{this.props.children | | this.props.text}

TextStyle
在React Native的
Text
组件上有意义,而在采用
cssprroperties
类型的
span
上则没有意义。这里的目标是什么?我的目标是:收集双方的共同领域(网络和本地)。Web有特定的风格道具,rn也有特定的风格道具。但也有共同的风格。开发人员可以选择React.cssprroperties或TextStyle。我认为更好的设计是创建一个类似以下内容的组件
(props:IBaseTextStyleType)=>isWeb?{…}:{…}
那太好了,但是。我刚刚为这两个项目创建了所有组件。据我所知,
在react原生项目中不起作用,是吗?它起作用了,谢谢。请将我的回复标记为答案:)
<span style={style.textStyle as React.CSSProperties}>
    {this.props.children || this.props.text}
</span>