You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the difference, and intended use case, for each of these 3 things? The documentation on ObjectSchema is very limited, and only appears to refer to it as a type and not as a class.
For example, what is the different between AccountSchemaA and AccountSchemaB in the code below?
interfaceAccount{username: string;email: string;phone: string;}constAccountSchemaA=newyup.ObjectSchema<Account>({username: yup.string().required(),email: yup.string().required(),phone: yup.string().required().matches(/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/,{message: 'Phone number must be in the format (XXX) XXX-XXXX',excludeEmptyString: true,}),});constAccountSchemaB: yup.ObjectSchema<Account>=yup.object({username: yup.string().required(),email: yup.string().required(),phone: yup.string().required().matches(/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/,{message: 'Phone number must be in the format (XXX) XXX-XXXX',excludeEmptyString: true,}),});
From what I can tell, adding an unexpected property to AccountSchemaA, like in the example below, gives an error, but this does not happen for AccountSchemaB.
The error is Object literal may only specify known properties, and 'bob' does not exist in type 'Shape<Account, AnyObject>'.ts(2353).
constAccountSchemaA=newyup.ObjectSchema<Account>({username: yup.string().required(),email: yup.string().required(),bob: yup.string(),phone: yup.string().required().matches(/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/,{message: 'Phone number must be in the format (XXX) XXX-XXXX',excludeEmptyString: true,}),});
Any details on this would be super helpful to make sure we are using this as intended and understand the tradeoffs between the two.
Thanks!
The text was updated successfully, but these errors were encountered:
It may be that AccountSchemaB would throw an error at compile time with the added bob property, but for AccountSchemaA this error shows up immediately in the editor.
there is no difference in behavior, the types are just different on the class vs the factory function. In general the types are going to be less accurate if you use the schema class directly. There are a lot of generics meant to be used in particular ways on them. Prefer the factory functions unless you are comfortable with complex generics
What is the difference, and intended use case, for each of these 3 things? The documentation on ObjectSchema is very limited, and only appears to refer to it as a type and not as a class.
For example, what is the different between
AccountSchemaA
andAccountSchemaB
in the code below?From what I can tell, adding an unexpected property to
AccountSchemaA
, like in the example below, gives an error, but this does not happen forAccountSchemaB
.The error is
Object literal may only specify known properties, and 'bob' does not exist in type 'Shape<Account, AnyObject>'.ts(2353)
.Any details on this would be super helpful to make sure we are using this as intended and understand the tradeoffs between the two.
Thanks!
The text was updated successfully, but these errors were encountered: