How to use the io-ts.failure function in io-ts

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

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elastic / kibana / x-pack / plugins / infra / server / lib / sources / types.ts View on Github external
runtimeTypes.string.validate(input, context).chain(stringInput => {
      const momentValue = moment(stringInput);
      return momentValue.isValid()
        ? runtimeTypes.success(momentValue.valueOf())
        : runtimeTypes.failure(stringInput, context);
    }),
  output => new Date(output).toISOString()
github tangdrew / fhir-ts / packages / primitives / src / R4 / string.ts View on Github external
  (m, c) => (isString(m) ? success(m) : failure(m, c)),
  identity
github celo-org / celo-monorepo / packages / contractkit / src / identity / claims / types.ts View on Github external
either.chain(t.string.validate(input, context), (stringValue) => {
      try {
        JSON.parse(stringValue)
        return t.success(stringValue)
      } catch (error) {
        return t.failure(stringValue, context, 'can not be parsed as JSON')
      }
    }),
  String
github gcanti / io-ts-types / src / JSON / JSONFromString.ts View on Github external
          return tryCatch(() => JSON.parse(s)).fold(() => t.failure(s, c), t.success)
        }
github gcanti / fp-ts-routing / src / index.ts View on Github external
either.chain(string.validate(u, c), s => {
      const n = +s
      return isNaN(n) || !Number.isInteger(n) ? failure(s, c) : success(n)
    }),
  String
github celo-org / celo-monorepo / packages / utils / src / io.ts View on Github external
(stringValue) =>
        isValidAddress(stringValue)
          ? t.success(toChecksumAddress(stringValue))
          : t.failure(stringValue, context, 'is not a valid address')
    ),
github gcanti / io-ts-types / src / fromRefinement.ts View on Github external
  return new t.Type(name, is, (u, c) => (is(u) ? t.success(u) : t.failure(u, c)), t.identity)
}
github Majavapaja / Majavashakki / src / common / types.ts View on Github external
baseType.validate(u, c).chain(val => {
        const valid = validators.every(v => v(val))
        return valid ? t.success(val) : t.failure(u, c, mkMessage(val))
      }),
    t.identity,
github celo-org / celo-monorepo / packages / utils / src / io.ts View on Github external
(stringValue) =>
        isE164NumberStrict(stringValue)
          ? t.success(stringValue)
          : t.failure(stringValue, context, 'is not a valid e164 number')
    ),
github tangdrew / fhir-ts / packages / primitives / src / R4 / integer.ts View on Github external
  (m, c) => (isInteger(m) ? success(m) : failure(m, c)),
  identity