javascript - 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; }>'。
如何解决此警告,在此先感谢。
解决方案
我通过以下代码解决了这个错误:
<View style={{ opacity: true ? 0.5 : 1 }}>
快乐编码!
推荐阅读
- asp.net-mvc-4 - 发布后选择下拉值
- angular - 角度元素如何订阅主机发出的事件?
- c# - 停靠背景图像 c#
- java - 获取Java中用户定义类的闭区间子集
- javascript - “vue.js 模板”属性或 javascript 模板文字中的苗条语法
- django - Django 休息框架 Reactjs 会话不起作用
- python-3.x - Python - 类实例共享类字典变量?
- javascript - 如何从用户那里获取 setInterval 的时间间隔
- git - Git 中的内部/外部合并是什么意思?
- angular - 将带有 json 数据的数组转换为带有 field 和 value 属性的数组