首页 > 解决方案 > React Native 中视图不透明度的类型“IntrinsicAttributes”抛出和错误不存在属性“不透明度”

问题描述

写完这句话后,打字稿文件在下面一行显示错误。

React-Native 0.60+ 有一个新的 opacity 属性可以传入:

<View opacity={true ? 0.5 : 1}> </View>

错误堆栈:类型“IntrinsicAttributes 和 IntrinsicClassAttributes 视图不透明度”上不存在错误属性“不透明度”。

没有重载匹配此调用。重载 1 of 2,'(props: ViewProps | Readonly): View',给出了以下错误。类型'{孩子:元素;不透明度:布尔值;}' 不可分配给类型 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; }>'。

类型“IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; 上不存在属性“不透明度” }>'。

Overload 2 of 2, '(props: ViewProps, context: any): View',给出了以下错误。类型'{孩子:元素;不透明度:布尔值;}' 不可分配给类型 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; }>'。

如何解决此警告,在此先感谢。

标签: javascriptreactjstypescriptreact-nativeeslint

解决方案


我通过以下代码解决了这个错误:

<View style={{ opacity: true  ? 0.5 : 1 }}>

快乐编码!


推荐阅读