io-ts-types
A collection of runtime types for use with io-ts
Last updated 9 years ago by gcanti .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install io-ts-types 
SYNC missed versions from official npm registry.

A collection of runtime types and combinators for use with io-ts

API

newtype-ts

fromNewtype

Given

import { Newtype, iso } from 'newtype-ts'

type Age = Newtype<'Age', number>

I want to define a runtime type whose derived type is

type Person = {
  name: string
  age: Age
}

Solution

import * as t from 'io-ts'
import { fromNewtype } from 'io-ts-types/lib/newtype-ts/fromNewtype'

const Person = t.interface({
  name: t.string,
  age: fromNewtype<Age>(t.Integer)
})

Usage example

import { iso } from 'newtype-ts'
import { Lens } from 'monocle-ts'

type Person = t.TypeOf<typeof Person>

const ageLens = Lens.fromProp<Person, 'age'>('age').composeIso(iso<Age>())

const sum = (a: number) => (b: number) => a + b

console.log(t.validate({ name: 'Giulio', age: 43 }, Person).map(ageLens.modify(sum(1))))
// => right({ name: 'Giulio', age: 44 })

Current Tags

  • 0.5.19                                ...           latest (4 years ago)
  • 0.3.5                                ...           next (9 years ago)
  • 0.4.8                                ...           old-version-0.4.x (7 years ago)

54 Versions

  • 0.5.19                                ...           4 years ago
  • 0.5.18                                ...           4 years ago
  • 0.5.17                                ...           4 years ago
  • 0.5.16                                ...           6 years ago
  • 0.5.15                                ...           6 years ago
  • 0.5.14                                ...           6 years ago
  • 0.5.13                                ...           6 years ago
  • 0.5.12                                ...           6 years ago
  • 0.5.11                                ...           6 years ago
  • 0.5.10                                ...           6 years ago
  • 0.5.9                                ...           6 years ago
  • 0.5.8                                ...           6 years ago
  • 0.5.7                                ...           6 years ago
  • 0.5.6                                ...           7 years ago
  • 0.5.5                                ...           7 years ago
  • 0.5.4                                ...           7 years ago
  • 0.4.8                                ...           7 years ago
  • 0.5.3                                ...           7 years ago
  • 0.5.2                                ...           7 years ago
  • 0.5.1                                ...           7 years ago
  • 0.5.0                                ...           7 years ago
  • 0.4.7                                ...           8 years ago
  • 0.4.6                                ...           8 years ago
  • 0.4.5                                ...           8 years ago
  • 0.4.4                                ...           8 years ago
  • 0.4.3                                ...           8 years ago
  • 0.4.2                                ...           8 years ago
  • 0.4.1                                ...           8 years ago
  • 0.4.0                                ...           8 years ago
  • 0.3.14                                ...           8 years ago
  • 0.3.13                                ...           8 years ago
  • 0.3.12                                ...           8 years ago
  • 0.3.11                                ...           8 years ago
  • 0.3.10                                ...           8 years ago
  • 0.3.9                                ...           8 years ago
  • 0.3.8                                ...           8 years ago
  • 0.3.7                                ...           8 years ago
  • 0.3.6                                ...           8 years ago
  • 0.3.5                                ...           9 years ago
  • 0.3.4                                ...           9 years ago
  • 0.3.3                                ...           9 years ago
  • 0.3.2                                ...           9 years ago
  • 0.3.1                                ...           9 years ago
  • 0.3.0                                ...           9 years ago
  • 0.2.5-rc                                ...           9 years ago
  • 0.2.4                                ...           9 years ago
  • 0.2.3                                ...           9 years ago
  • 0.2.2                                ...           9 years ago
  • 0.2.1                                ...           9 years ago
  • 0.2.0                                ...           9 years ago
  • 0.1.1                                ...           9 years ago
  • 0.1.0                                ...           9 years ago
  • 0.0.2                                ...           9 years ago
  • 0.0.1                                ...           9 years ago
Maintainers (1)
Downloads
Total 191
Today 0
This Week 0
This Month 191
Last Day 32
Last Week 191
Last Month 0
Dependencies (4)
Dev Dependencies (8)

© 2010 - cnpmjs.org x YWFE | Home | YWFE