How to fix “Type '{}' is missing in the following properties…” error in Typescript?

Asked
Active3 hr before
Viewed126 times

2 Answers

errortypescript
90%

Stack Overflow en español, Meta Stack Overflow ,Stack Overflow em Português

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;
}
load more v
88%

TypeScript error: Type '{}' is missing the following properties from type 'Readonly<RcBaseFormProps & Pick<SetupFormProps, "username" | "email" | "password" | "confirm_password" | "first_name" | "last_name">>': username, email, password, confirm_password, and 2 more. TS2740

Đây là mã:

import React, { useState } from 'react';
import { Form, Input, Row, Col } from 'antd';
import { FormComponentProps } from 'antd/lib/form';


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

const SetupForm: React.FC<SetupFormProps> = ({ form }) => {
  ...
  return (
    <Form id="setup-form" layout="vertical" onSubmit={handleSubmit}>...</Form>
  )
}

export default Form.create<SetupFormProps>({ name: 'register' })(SetupForm);

và trong thành phần khác của tôi, tôi đang truy cập nó theo cách này:

import SetupForm from './form';

<SetupForm />
load more v

Other "error-typescript" queries related to "How to fix “Type '{}' is missing in the following properties…” error in Typescript?"