0

This is my first time using the prop-types library.

This is my error message.

  • Binding element 'name' implicitly has an 'any' type.
  • Binding element 'email' implicitly has an 'any' type.
  • Binding element 'gender' implicitly has an 'any' type.

This is my code.

import PropTypes from "prop-types";

export default function Row({ name, email, gender }) {
  return (
    <>
      <p>{name}</p>
      <p>{email}</p>
      <p>{gender}</p>
    </>
  );
}

Row.propTypes = {
  name: PropTypes.string,
  email: PropTypes.string,
  gender: PropTypes.string,
};

I think there is not wrong part. I need you help how can i fix my error without 'interface' or 'type'.

3
  • If this is typescript then you don't need PropTypes Commented Mar 7, 2021 at 9:33
  • Check reactjs.org/docs/typechecking-with-proptypes.html Commented Mar 7, 2021 at 9:40
  • That's something I was completely mistaken about. Thank you so much! Commented Mar 7, 2021 at 9:44

1 Answer 1

1

It appears you're writing Typescript as opposed to Javascript.

Proptypes is used to achieve the idea of static typing in Javascript, but if you're writing Typescript then you need to define an interface for your props like this.

interface Props {
  name: string;
  email: string;
  gender: string;
}

export default function Row({ name, email, gender }: Props) {
  return (
    <>
      <p>{name}</p>
      <p>{email}</p>
      <p>{gender}</p>
    </>
  );
}
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't know properly from the first premise. Thank you!!

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.