首页 > 解决方案 > 类型 IntrinsicClassAttributes 上不存在属性

问题描述

我必须承认这是我在 ReactNative 世界中的第一步。

我尝试升级所有 npm 库,如果我运行 build 命令,我会遇到很多错误,例如:

Property 'underlayColor' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Button> & Readonly<ButtonProps> & Readonly<{ children?: ReactNode; }>'.

Property 'backgroundColor' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Button> & Readonly<ButtonProps> & Readonly<{ children?: ReactNode; }>'.

Property 'textStyle' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Button> & Readonly<ButtonProps> & Readonly<{ children?: ReactNode; }>'.

等等

这很奇怪,因为我做了快速研究,上面的属性可用于 element. 我的问题是:我应该添加额外的库或构建元素吗?或者也许在最新版本的 react native 中,Button 组件的属性真的被禁用了?

编辑 我的代码的示例部分:错误是关于缺少 underlayColor

<View style={[styles.modal.footer]}>
    <Button
     buttonStyle={styles.common.buttonTransparent}
     onPress={() => requestAnimationFrame(() => this.setState({isModalVisible: false}))}
     title={I18n.t('CANCEL')}
     underlayColor={styles.palette.transparent}
     textStyle={styles.modal.actionButtonText}
     containerViewStyle={styles.modal.actionButtonContainer}
    />
    <Button
     buttonStyle={styles.common.buttonTransparent}
     onPress={this.createReport}
     title={I18n.t('CREATE')}
     underlayColor={styles.palette.transparent}
     textStyle={styles.modal.actionButtonText}
     containerViewStyle={styles.modal.actionButtonContainer}
    />
</View>

标签: react-nativereact-native-android

解决方案


错误表明textStyle并且underlayColor不是您的组件的有效道具Button。好像您从某个库中导入了按钮。仔细检查您的图书馆文档。

另外,请检查您的样式,它应该包含backgroundColor无效的样式。


推荐阅读