export interface IWEProps {
accessibilityLabel: string;
onPress?: ((status: string | undefined) => void) | undefined;
localePrefix: string;
children: JSX.Element[];
style: IWEStyle;
type?: string;
}
class WrappingElement extends React.PureComponent<IWEProps> {
render() {
const {
onPress, children, type, accessibilityLabel, style,
} = this.props;
return onPress ? (
<TouchableOpacity
accessibilityLabel={accessibilityLabel}
style={style}
type={type}
onPress={() => onPress(type)}
>
{ children }
</TouchableOpacity>
) : (
<View
accessibilityLabel={accessibilityLabel}
style={style}
type={type}
>
{ children }
</View>
);
}
}
这就是我正在做的,这是一个错误,我在View
和TouchableOpacity
中获得type
prop:
属性'type'不存在类型'IntrinsicAttributes &IntrinsicClassAttributes,只读"。
错误信息是直接的:组件View
和TouchableOpacity
不存在proptype
。View可用的props在这里有文档说明。TouchableOpacity可用的props在这里有文档。
由于您在WrappingElement
中没有使用type
做任何事情,而不是将其传递给View
和TouchableOpacity
以及onPress
函数,您可以删除此道具。下面的代码与您的代码相同,但不会抛出类型错误。
export interface IWEProps {
accessibilityLabel: string;
onPress?: ((status: string | undefined) => void) | undefined;
localePrefix: string;
children: JSX.Element[];
style: IWEStyle;
type?: string;
}
class WrappingElement extends React.PureComponent<IWEProps> {
render() {
const {
onPress, children, type, accessibilityLabel, style,
} = this.props;
return onPress ? (
<TouchableOpacity
accessibilityLabel={accessibilityLabel}
style={style}
onPress={() => onPress(type)}
>
{ children }
</TouchableOpacity>
) : (
<View
accessibilityLabel={accessibilityLabel}
style={style}
>
{ children }
</View>
);
}
}