scotthovestadt / schema-object

Enforce schema on JavaScript objects, including type, transformation, and validation. Supports extends, sub-schemas, and arrays.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a problem with nested arrays?

raducretu opened this issue · comments

commented

Hello I've been trying to nest some arrays and I cannot seem to make it to work, is it me or maybe a small bug?

const AvailabilitySpecific = {
    date: String,
    intervals: [[Number]]
}

export default new SchemaObject({
    days: AvailabilityDays,
    empty: [String],
    specific: {
        type: [AvailabilitySpecific],
        default: [{
            date: '2020-10-10',
            intervals: [[520, 940]]
        }]
    }
},{
    setUndefined: true
})

this will set the default for the date but not for the intervals, and it's the same if I call new

also the expanded version produces the same empty array for specific

const AvailabilitySpecific = {
    date: String,
    intervals: {
        type: Array,
        arrayType: {
            type: Array,
            arrayType: {
                type: Number
            }
        }
    }
}

Never actually tried to nest Arrays! There are no test cases for it. I'll see if I can isolate the issue and push up a fix.