Skip to main content Link Menu Expand (external link) Document Search Copy Copied

getLenses overview

Added in v0.5.0


Table of contents


ExactHasLenses (interface)

Signature

export interface ExactHasLenses extends t.ExactType<HasLenses> {}

Added in v0.5.0

HasLenses (type alias)

Signature

export type HasLenses = t.InterfaceType<any> | ExactHasLenses

Added in v0.5.0

getLenses

Return a Lens for each prop

Signature

export function getLenses<C extends HasLenses>(
  codec: C
): { [K in keyof t.TypeOf<C>]: Lens<t.TypeOf<C>, t.TypeOf<C>[K]> } { ... }

Example

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

const Person = t.type({
  name: t.string,
  age: t.number
})

const lenses = getLenses(Person)
assert.strictEqual(lenses.age.get({ name: 'Giulio', age: 44 }), 44)

Added in v0.5.0