Skip to content
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

Handle sparse array positions as undefined V2 #950

Merged

Conversation

VanTanev
Copy link
Contributor

@VanTanev VanTanev commented Jun 24, 2020

Superseeds #949; Fixes #676

Yup validation no longer throws on sparse arrays:

let schema = y.array(number())
let arr = []
arr[1] = 1
arr
// => [empty, 1]

// fixes TypeError: Cannot read property 'fulfilled' of undefined
schema.validate(arr, {
  abortEarly: false,
  context: {},
})

Yup required validation now treats empty slots in sparse arrays as missing:

let schema = y.array(y.number().required())
let arr = []
arr[1] = 1
arr
// => [empty, 1]

await schema.isValid(arr) // false
await schema.compact().isValid(arr) // true

Yup preserves empty slots in sparse arrays when valid:

let schema = y.array(y.number())
let arr = []
arr[1] = 1
arr
// => [empty, 1]

let value = await schema.validate(arr)

0 in value 
// => false

@jquense
Copy link
Owner

jquense commented Jun 24, 2020

#949 (comment)

@VanTanev VanTanev force-pushed the handle-sparse-arrays-no-fill-undefined branch from d9ce626 to a18d75d Compare June 25, 2020 08:20
src/array.js Outdated Show resolved Hide resolved
test/array.js Outdated Show resolved Hide resolved
test/array.js Outdated Show resolved Hide resolved
test/array.js Outdated Show resolved Hide resolved
@VanTanev VanTanev force-pushed the handle-sparse-arrays-no-fill-undefined branch from a18d75d to dc9f4a0 Compare June 25, 2020 14:22
@VanTanev VanTanev requested a review from jquense June 25, 2020 14:24
src/array.js Show resolved Hide resolved
@jquense jquense merged commit 4e77348 into jquense:master Jun 26, 2020
@jquense
Copy link
Owner

jquense commented Jun 26, 2020

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read property 'fulfilled' of undefined
2 participants