Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Binding element 'message' implicitly has an 'any' type

i want to pass information from parent to son, but i get error: Binding element ‘message’ implicitly has an ‘any’ type. What to do? Please help my code:

const Forms = () => {
    const [messageText, setMessageText] = useState("");

    useEffect(() => {
        API.getPosts()
        const handleMessage = () => {
            setMessageText("lox");
        }
    }, [])

    return (
        <div>
            <div style={{alignItems: "center", justifyContent: "center", textAlign: "center"}}>
                <Form message={messageText}/>
                <Form message={messageText}/>
            </div>

        </div>
    );
};

export default Forms; 

Son

const Form = ({message}) => {
    return (
        <div>
                <div className={form.form}>
                <h2 className={form.text}>{message}</h2>
                    <p>Автор: <span style={{textDecoration: "underline"}}>Author</span></p>
                </div>

        </div>
    );
};

export default Form; 

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To fix this error, you can define the type of the message variable like the code below:

const Form = ({ message }: { message: string }) => {
  return (
    <div>
      <div className={form.form}>
        <h2 className={form.text}>{message}</h2>
        <p>
          Автор: <span style={{ textDecoration: "underline" }}>Author</span>
        </p>
      </div>
    </div>
  );
};

export default Form;

you could use the any type explicitly if you don’t know the type of the message variable, like so: { message }: { message: any}.
However, using any should be avoided if possible because it undermines the benefits of using TypeScript.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading