Typescript 类型';PartialDeep<;StringSchema>';不可分配给类型';图式<;{}>';。TS2345
我在使用typescript提取JSON对象的值时遇到了这个错误 这是JSON对象:Typescript 类型';PartialDeep<;StringSchema>';不可分配给类型';图式<;{}>';。TS2345,typescript,lodash,typescript3.0,Typescript,Lodash,Typescript3.0,我在使用typescript提取JSON对象的值时遇到了这个错误 这是JSON对象: const schema = { firstName: yup .string() .required(REQUIRED_FIELD_MESSAGE) .min(1) .max(50) } 我有一个字符串[]: list = [ "firstName" ] 然后使用pick仅从const schema获取键值对,如果我使用: pick(schema, l
const schema = {
firstName: yup
.string()
.required(REQUIRED_FIELD_MESSAGE)
.min(1)
.max(50)
}
我有一个字符串[]:
list = [
"firstName"
]
然后使用pick仅从const schema获取键值对,如果我使用:
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
属性“firstName”的类型不兼容。
类型“PartialDeep | undefined”不可分配给类型“Ref | Schema | undefined”。
类型“PartialDeep”不可分配给类型“Ref | Schema | undefined”。
类型“PartialDeep”不可分配给类型“Schema”。TS2345