I am encountering an issue when using the yup validation library in my Next TS project. I am receiving a type error on the type property under the PostWithSig object in my validation schema. I am unsure of the cause of this error one possibility is the name type
itself but I am not sure about it.
Here is the error message I am receiving:
(property) BaseSchema<any, any, any>.type: string Type 'RequiredStringSchema<string | undefined, AnyObject>' is not assignable to type 'string'.ts(2322) schema.d.ts(53, 14): The expected type comes from property 'type' which is declared here on type 'AnySchema<any, any, any>'
Here is my validation schema:
data: object().shape({
createPostTypedData: object().shape({
id: string().required(),
expiresAt: date().required(),
typedData: object().shape({
types: object().shape({
PostWithSig: array().of({
name: string().required(),
type: string().required(),
}),
}),
domain: object().shape({
name: string().required(),
chainId: number().required(),
version: string().required(),
verifyingContract: string().required(),
}),
value: object().shape({
nonce: number().required(),
deadline: number().required(),
profileId: string().required(),
contentURI: string().required(),
collectModule: string().required(),
collectModuleInitData: string().required(),
referenceModule: string().required(),
referenceModuleInitData: string().required(),
}),
}),
}),
}),
Can anyone explain why I am encountering this error and provide a solution to fix it?
CodePudding user response:
Took me a while to realize that you had forgot to use an object schema:
array().of(object().shape({
name: string().required(),
type: string().required(),
})),