0
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>
    );
  }
}

This is what I am doing, and this is an error I'm getting on type prop in View and TouchableOpacity:

Property 'type' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'.

1 Answer 1

1

The error message is straight forward: The prop type does not exist for the components View and TouchableOpacity. The available props for View are documented here. The available props for TouchableOpacity are documented here.

Since you are not doing anything with type in WrappingElement other than passing it to View and TouchableOpacity and the onPress function, you can just remove this prop. The following code is equivalent to yours, but does not throw the type error.

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>
    );
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I am using a type property. Deleting this one from props, unfortunately, is not solving my issue
No, removing this one from View and TouchableOpacity. You can keep it for WrappingElement and pass it to onPress as before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.