且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何修复“以下属性中缺少类型 '{}'...";打字稿错误?

更新时间:2022-01-09 22:10:04

props 接口中的所有 props 都是必需的(它们不能被 undefined)

All the props in your props interface are required (they can't be undefined)

interface SetupFormProps extends FormComponentProps {
  username: string;
  email: string;
  password: string;
  confirm_password: string;
  first_name: string;
  last_name: string;
}

但是你在使用你的组件时没有从界面中指定 props

But you are using your component without specifying the props from the interface

<SetupForm />

所以你应该从界面(SetupFormProps)中指定道具

So you should either specify the props from the interface (SetupFormProps)

<SetupForm username="myUserName" ...etc />

或者让道具可选

interface SetupFormProps extends FormComponentProps {
  username?: string;
  email?: string;
  password?: string;
  confirm_password?: string;
  first_name?: string;
  last_name?: string;
}