如何在我的React类的接口中包含接口?

时间:2019-12-05 17:34:24

标签: javascript reactjs typescript interface

由于我的Class道具界面为空,因此出现了错误提示。我正在此组件中使用其他接口。

这是我的代码:

import React from 'react';
import axios from 'axios';
import { Button } from '@material-ui/core';
// import { Form, Field } from 'react-final-form';
// import {TextField} from 'final-form-material-ui';

// tslint:disable-next-line
interface CompanyFinancialModalFormProps {}
export interface IValues {
  company_name: string;
  critical_technology: [];
}
export interface IFormState {
  [key: string]: any;
  values: IValues[];
  submitSuccess: boolean;
}

export default class CompanyFinancialModalForm extends React.Component<CompanyFinancialModalFormProps, IFormState> {
  constructor(props: CompanyFinancialModalFormProps) {
    super(props);
    this.state = {
      company_name: '',
      critical_technology: [],
      values: [],
      submitSuccess: false
    };
  }

  public render() {
    const {} = this.state;

    return (
      <div>
        <form>
          <div className='submit-button-wrapper'>
            <Button aria-label='home' className={'submit-button'} type='submit'>
              Add Company
            </Button>
          </div>
        </form>
      </div>
    );
  }
}

如何构造此权限,这样就不必使用// tslint:disable-next-line

1 个答案:

答案 0 :(得分:2)

这既不是TypeScript也不是React错误消息。

您的linter(tsLint)已启用no-empty-interface rule

说实话,我只是停用该规则。 (为此,请查看您的tslint.json)即使将Props(现在)为空,也将其指定为接口的用例是完全有效的-这样,您以后就可以指定更多的props,而不必担心忘记了在某处输入该类型。

并非每个短绒规则都“通常有用”。在这里,事实并非如此。