Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Make s.object() confirm to the standard matcher(options) #39

Open
rprieto opened this issue Mar 7, 2016 · 3 comments
Open

Make s.object() confirm to the standard matcher(options) #39

rprieto opened this issue Mar 7, 2016 · 3 comments

Comments

@rprieto
Copy link
Contributor

rprieto commented Mar 7, 2016

Strummer matchers usually have several forms:

  • a canonical version which takes options, like like s.array({of: matcher, min :1})
  • shorthand helpers like s.array(matcher)

object is the only exception, because the canonical version is s.object(fields). This means the matcher can never have an other options. It would be a breaking change, but I suggest we should change to s.object({props: ...}), which would allow for things like

s.object({
  optional: true,     // can be null
  allowExtra: true,   // don't fail if there's additional properties to the ones below
  props: { ... }      // list of properties
})

We could still have the top-level shorthand s(someObject) which would delegate to s.object({props: someObject}).

Note: this would remove the need for s.objectOnly.

@kiddkai
Copy link
Contributor

kiddkai commented Mar 7, 2016

sounds good to me~

@FagnerMartinsBrack
Copy link

Could also do something like:

s.object({with: properties})

Which would kind of be read in a similar way as "object with only properties", just now it would be "object with properties" (which IMHO is much more fluent).

It is very important that we run strict comparisons by default and only allow ignoring properties if explicitly asking to do so.

👍

@rprieto
Copy link
Contributor Author

rprieto commented Mar 7, 2016

👍 for s.object({with: properties})

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

No branches or pull requests

4 participants
@rprieto @FagnerMartinsBrack @kiddkai and others