类型'PartialDeep <stringschema>'不能分配给类型'Schema <{}>'。 TS2345

时间:2019-04-15 00:59:05

标签: typescript lodash typescript3.0

使用lodash pick提取JSON对象的值时,我在打字稿中遇到此错误。

这是JSON对象:

const schema = {
  firstName: yup
   .string()
   .required(REQUIRED_FIELD_MESSAGE)
   .min(1)
   .max(50)
}

我有一个字符串[]:

list = [
        "firstName"
     ]

然后使用pick从const模式中仅获取键值对,如果我使用的话:

pick(schema, list)

我收到以下错误

Types of property 'firstName' are incompatible.
    Type 'PartialDeep<StringSchema> | undefined' is not assignable to type 'Ref | Schema<{}> | undefined'.
      Type 'PartialDeep<StringSchema>' is not assignable to type 'Ref | Schema<{}> | undefined'.
        Type 'PartialDeep<StringSchema>' is not assignable to type 'Schema<{}>'.  TS2345

0 个答案:

没有答案