本文介绍了TS2739-以下属性中缺少类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我用钩子连接Typescript.当我尝试在父组件中呈现注册用户"时,出现错误:

So i connect Typescript with hooks.When i try to render Register User in parent component i getting error:

  interface IRegisterUser {
    mail: string;
    password: string;
  };

  let RegisterUser: React.FC<IRegisterUser> = (props) => {

    const InitialUserState = {mail: "", password: ""}
    const [user, setUser] = useState(InitialUserState)

    useEffect(() => {

    }, []);

    return (
        <div>
                <input type="text" className="text" name="username" value={user.mail}  placeholder="" required/>
                <input type="text" className="text" name="userpassword" value={user.password}  placeholder="" required/>
        </div>
    );
  }

推荐答案

给出您的评论:

RegisterUser 应该通过道具接收邮件密码.

The RegisterUser should not receive mail and password via props.

props 设为可选.

interface IRegisterUser {
  mail?: string;
  password?: string;
};

这篇关于TS2739-以下属性中缺少类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:22