simple-runtypes icon indicating copy to clipboard operation
simple-runtypes copied to clipboard

nonStrict modifier

Open hoeck opened this issue 3 years ago • 0 comments

Change the existing sloppyRecord runtype functionality into a nonStrict combinator that works on record runtypes, similar to how pick works atm.

Before:

import * as st from 'simple-runtypes'

const item = st.sloppyRecord({
  id: st.number(),
  label: st.string(),
})

After:

import * as st from 'simple-runtypes'

const item = st.nonStrict(
    st.record({
        id: st.number(),
        label: st.string(),
    }),
)

Reasons:

  • "sloppy" has a bad connotation that looks weird when spread out all over runtype definitions
  • using a modifier function allows for separating the record definition from the way its parsed
  • it is still possible to mix nonStrict with strict objects in a single runtype

hoeck avatar Jul 14 '22 14:07 hoeck