TS2739 - Type missing in following properties

我与影子孤独终老i 提交于 2021-01-29 20:20:44

问题


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

回答1:


Given your comment:

user should provide mail + password

The RegisterUser should not receive mail and password via props.

Make the props optional.

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


来源:https://stackoverflow.com/questions/58181194/ts2739-type-missing-in-following-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!