在 React TypeScript 中将文件作为道具传递(类型 'true' 不可分配给类型 'ChangeEventHandler<HTMLInputElement>)

passing file as prop in react typescript (Type 'true' is not assignable to type 'ChangeEventHandler<HTMLInputElement>)

我正在用 reactjs 写一个应用程序

我想上传作为 prop 从子组件传递到父组件的文件

子组件

const RegisterIndividual: React.FC< { upload_id_card: React.ChangeEventHandler<HTMLInputElement>} > = ({
  upload_id_card,
  handleInput }) => {

  return (
    <div className="mt-3">

          <input
            type="file"
            name="profile_picture"
            id=""
            onChange=={upload_id_card}
            style={{ display: "block", marginTop: "1rem" }}
          />
     </div>
)};

父组件

const Register = () => {
const upload_id_card = (event) => {
    console.log("type upload file code here")
  }
  return (
    <div className="__register">
    <RegisterIndividual upload_id_card={upload_id_card} />
    </div>
)}

但我在子组件上收到此错误

Type 'true' is not assignable to type 'ChangeEventHandler<HTMLInputElement> | undefined'.ts(2322)

删除==并替换为=,你想分配而不是比较:

onChange=={upload_id_card}