Skema: Strict Basic Types
How to use skema as the type checker
by kaelzhang
HTML
<script src="https://unpkg.com/skema/umd/jsfiddle.js"></script>
<script src="https://unpkg.com/skema/umd/skema.min.js"></script>
JavaScript
const {
defaults,
BASIC_TYPES
} = Skema
const {
shape
} = defaults({
// Changes default settings, and the basic types are strict now.
types: BASIC_TYPES.STRICT
})
const StrictUser = shape({
id: Number,
name: String
})
throws(() => StrictUser.from({
id: '123',
name: 'Steve'
}))
success(StrictUser.from({
id: 123,
name: 'Steve'
}))