js-schema icon indicating copy to clipboard operation
js-schema copied to clipboard

How to validate only given properties exist?

Open trusktr opened this issue 10 years ago • 1 comments

How do we specify that any fields other than the ones specified are not allowed? SO, f.e., I want this:

var Thing = schema({
  foo: Number
})

Thing({foo: 5}) // true
Thing({foo: 5, bar: "blah"}) // false, because `blah` isn't a specified property.

trusktr avatar Jul 17 '15 04:07 trusktr

This might be way to late for an answer, but I found myself looking for the same answer and ended up using something like this: Thing:{ "*":Object.like(undefined), foo:5 }

matsuki820 avatar Mar 24 '16 11:03 matsuki820