-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tuple describe() method #1947
Tuple describe() method #1947
Conversation
src/locale.ts
Outdated
@@ -136,7 +136,7 @@ export let array: Required<ArrayLocale> = { | |||
export let tuple: Required<TupleLocale> = { | |||
notType: (params) => { | |||
const { path, value, spec } = params; | |||
const typeLen = spec.types.length; | |||
const typeLen = spec.innerType.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd rather keep the types
name, i wanted to migrate array to use it it as well but opted to avoid the breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I can change that back to types
. I suppose that is actually a breaking change too, so it should remain types
. Its a bummer I didn't get to this before the official release of V1 🤷
What should I do with Array?
1 - Return it to its current shape (no spec)
2 - Add spec.innerType = {...the one type}
3 - Add spec.types = [{ ...the one type }]
// note the array
4 - Add spec.types = { ...the one type }
// note no array
5 - Add spec.type = { ...the one type }
// note spec is singular
I am leaning towards option 3. It seems most consistent with Tuple. And if there is ever another use case for some "inner type", then the property types
with an array is flexible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think 3 makes sense to me 👍
While I've got your eyes on this, this appears to be a bug in the array schema: Line 272 in b0e67ef
Shouldn't that pass innerOptions ?
|
@jquense All updates have been made. let me know if you have anymore questions or concerns. |
thanks! |
This PR addresses: #1891
The code aims to standardize how Array and Tuple inner types are configured. Historically
array
has stored it's one inner type on a propinnerType
. Tuple has stored its types inspec.types
. The types MUST be stored on thespec
object for Tuple because it is needed for thenotType
method. See:yup/src/locale.ts
Line 137 in f37a53f
Both Array and Tuple now have
schema.innerType
andschema.spec.innerType
. This was done for backwards compatibility and consistency. And all corresponding methods and types have been updated.This now allows the Tuple to return information about its types in the
describe
methodLet me know if you have any questions!