问题
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