Skip to content

Array object with optional key creates empty array with default value #10

Description

@adamjkb

In an array object schema the default value is partially ignore if the object schema contains optional keys.

const doc = syncroState({
  schema: {
    optionalInternal: y.array(y.object({
      value: y.string().optional()
    })).default([{ value: 'A' }, {value: 'B'}, {value: 'C'}]),
  }
})

In the above example the value of doc.optionalInternal initially is an empty array instead of the defined default value. If the key inside the object is nullable or "required" the state is matching expectation.

Reproduction

https://svelte.dev/playground/0afcdaa991bf4a15b5e947886cac53b0?version=latest

Additional information

A simpler array schema matches my expectation of how this should behave

y.array(y.string().optional()).default(['1','2']) // ['1','2']

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions