使用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