将"可触摸不透明度"与主透明一起使用会导致打字稿错误



下面是我尝试使用打字稿和 react-native 执行的代码,它在 VSCODE IDE 中给了我打字稿错误

import { TouchableOpacity } from "react-native";
<TouchableOpacity
primary
transparent
onPress={this.send}
>
<Text style={styles.btnText}>Send</Text>
</TouchableOpacity>

在VSCode中给出以下打字稿错误:

(alias) class TouchableOpacity
import TouchableOpacity
No overload matches this call.
Overload 1 of 2, '(props: Readonly<TouchableOpacityProps>): TouchableOpacity', gave the following error.
Type '{ children: Element; primary: true; transparent: true; onPress: () => void; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<TouchableOpacity> & Readonly<TouchableOpacityProps> & Readonly<{ children?: ReactNode; }>'.
Property 'primary' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<TouchableOpacity> & Readonly<TouchableOpacityProps> & Readonly<{ children?: ReactNode; }>'.
Overload 2 of 2, '(props: TouchableOpacityProps, context?: any): TouchableOpacity', gave the following error.
Type '{ children: Element; primary: true; transparent: true; onPress: () => void; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<TouchableOpacity> & Readonly<TouchableOpacityProps> & Readonly<{ children?: ReactNode; }>'.
Property 'primary' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<TouchableOpacity> & Readonly<TouchableOpacityProps> & Readonly<{ children?: ReactNode; }>'.ts(2769)

不要使用TouchableOffacity中不可用的道具。

<TouchableOpacity
style={{ backgroundColor: 'transparent' }}
onPress={this.send}
>

相关内容

最新更新