Typescript 如何将react javascript转换为类型脚本? 从“React”导入React; 从“antd”导入{DatePicker,Form,Input,TimePicker,Select}; const FormItem=表单项; const{Option}=Select; const CreateAntField=AntComponent=>({ 领域 形式, 标签, 选择选项, 提交帐户, 类型, …道具 }) => { const toucted=form.toucted[field.name]; const submitted=submitCount>0; const hasError=form.errors[field.name]; const submittedError=hasrerror&&submited; const touchedError=hasError&&touched; const onInputChange=({target:{value}})=> form.setFieldValue(field.name,value); const onChange=value=>form.setFieldValue(field.name,value); const onBlur=()=>form.setFieldTouched(field.name,true); 返回( {选择选项&& 选择Options.map(name=>{name})} ); };

Typescript 如何将react javascript转换为类型脚本? 从“React”导入React; 从“antd”导入{DatePicker,Form,Input,TimePicker,Select}; const FormItem=表单项; const{Option}=Select; const CreateAntField=AntComponent=>({ 领域 形式, 标签, 选择选项, 提交帐户, 类型, …道具 }) => { const toucted=form.toucted[field.name]; const submitted=submitCount>0; const hasError=form.errors[field.name]; const submittedError=hasrerror&&submited; const touchedError=hasError&&touched; const onInputChange=({target:{value}})=> form.setFieldValue(field.name,value); const onChange=value=>form.setFieldValue(field.name,value); const onBlur=()=>form.setFieldTouched(field.name,true); 返回( {选择选项&& 选择Options.map(name=>{name})} ); };,typescript,formik,ant-design-pro,Typescript,Formik,Ant Design Pro,我是typescript新手,我需要将此文件转换为typescript,这是一个ant设计组件。 我有以下错误: “field”隐式具有“any”类型。 “form”隐式具有“any”类型。 “label”隐式具有“any”类型。 “选择选项”隐式具有“任意”类型。 “submitCount”隐式具有“any”类型。 参数“name”隐式具有“any”类型。 参数“value”隐式具有“any”类型。 参数“value”隐式具有“any”类型。 参数“value”隐式地有一个“any”类型。在t

我是typescript新手,我需要将此文件转换为typescript,这是一个ant设计组件。 我有以下错误:

“field”隐式具有“any”类型。 “form”隐式具有“any”类型。 “label”隐式具有“any”类型。 “选择选项”隐式具有“任意”类型。 “submitCount”隐式具有“any”类型。 参数“name”隐式具有“any”类型。 参数“value”隐式具有“any”类型。 参数“value”隐式具有“any”类型。
参数“value”隐式地有一个“any”类型。

tsconfig.json
中尝试将
noImplicitlyAny
标志设置为false,但我将把它转换为false。这很好,让我们一步一步地迁移应用程序。您需要很多时间才能打开
noImplicitlyAny
标志,因为您必须手动键入大多数错误。


import React from "react";
import { DatePicker, Form, Input, TimePicker, Select } from "antd";

const FormItem = Form.Item;
const { Option } = Select;

const CreateAntField = AntComponent => ({
  field,
  form,
  label,
  selectOptions,
  submitCount,
  type,
  ...props
}) => {
  const touched = form.touched[field.name];
  const submitted = submitCount > 0;
  const hasError = form.errors[field.name];
  const submittedError = hasError && submitted;
  const touchedError = hasError && touched;
  const onInputChange = ({ target: { value } }) =>
    form.setFieldValue(field.name, value);
  const onChange = value => form.setFieldValue(field.name, value);
  const onBlur = () => form.setFieldTouched(field.name, true);
  return (
    <Form className="field-container">
      <FormItem
        label={label}
        help={submittedError || touchedError ? hasError : false}
        validateStatus={submittedError || touchedError ? "error" : "success"}
      >
        <AntComponent
          {...field}
          {...props}
          onBlur={onBlur}
          onChange={type ? onInputChange : onChange}
        >
          {selectOptions &&
            selectOptions.map(name => <Option key={name}>{name}</Option>)}
        </AntComponent>
      </FormItem>
    </Form>
  );
};