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

Create schema without default values #696

Open
macmillen opened this issue Aug 26, 2024 · 1 comment
Open

Create schema without default values #696

macmillen opened this issue Aug 26, 2024 · 1 comment

Comments

@macmillen
Copy link

When creating schemas I don't always want to set initial values.

Let's say we want to describe this type in a schema:

type ComponentMap = Record<string, { id: string; name: string; }>;

How the current schema builder works is that you have to pass in default values like so:

s.obj({
  key: s.obj({
    id: s.con(""),
    name: s.con("")>
  })
})

There are a couple of problems with this:

  1. we have a default value { key: { id: "", name: "" } } that we have to override
  2. we have a key key but in this case I just want to have a Record<string, ...>

Ideas:

  • make default values optional or provide an option noDefaultValues
  • provide a s.record() schema type like zod does

Examples:

s.record(
  s.con<string>(), 
  s.obj({ 
    id: s.con<string>(), 
    name: s.con<string>() 
  })
)
@macmillen
Copy link
Author

I found out that there is a .map builder which solves issue 2. but issue 1. still remains

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

No branches or pull requests

1 participant