将TouchableOpacity与主透明一起使用会产生打字错误

时间:2019-11-25 05:41:37

标签: typescript react-native visual-studio-code

下面是我试图使用打字稿和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)

1 个答案:

答案 0 :(得分:0)

请勿使用TouchableOffacity中不可用的道具。

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