How to use the runtypes.Constraint function in runtypes

To help you get started, we’ve selected a few runtypes examples, based on popular ways it is used in public projects.

github typeetfunc / runtypes-generate / src / custom.spec.ts View on Github external
const ArrayWithContains = (arrRt, item, count) => (args => Constraint(arrRt, list => {
  const res = contains(
    list, args,
    () => true,
    (_, res) => `Array contains less than ${res.needCount} items`,
    (_, res) => `Array contains more than ${res.needCount} items`
  );

  return res;
}, args))({tag: contains.name, count, item})