首页 > 解决方案 > 用是的缺少属性反应正式打字稿

问题描述

我的问题是。我试图在 typescript 环境下使用 react-formal 和 yup。

我有这样非常简单的代码,这给了我错误:

import React from 'react';
import * as yup from 'yup';
import { ObjectSchema } from 'yup';
import Form from 'react-formal';

interface ITest {
  name: string;
}
const FormalTest: React.FC = () => {
  const schema: ObjectSchema<ITest> = yup.object<ITest>( {
    name: yup.string().required().default( 'default' ),
  } );

  return (
    <div>
      <Form schema={ schema } defaultValue={ schema.default() }>
        <Form.Field name="name" />
      </Form>
    </div>
  );
};

VS Code 在线引发错误<Form schema={ schema } defaultValue={ schema.default() }>

Type 'ObjectSchema<ITest>' is missing the following properties from type 'ObjectSchema<object | undefined, object>': unknown, snakeCase, defined, optional, and 2 more.  TS2740

我真的不知道问题是什么。

你有什么想法/建议吗?我不能从打字稿辞职。

我正在使用“react-formal”:“2.1.3”,“yup”:“0.28.3”,“react”:“16.12.0”,

标签: reactjstypescript

解决方案


推荐阅读