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

IntFromString overview

Added in v0.4.4


Table of contents


IntFromStringC (interface)

Signature

export interface IntFromStringC extends t.Type<t.Int, string, unknown> {}

Added in v0.4.4

IntFromString

A codec that succeeds if a string can be parsed to an integer

Signature

export const IntFromString: IntFromStringC = ...

Example

import { IntFromString } from 'io-ts-types/lib/IntFromString'
import { right } from 'fp-ts/lib/Either'
import { PathReporter } from 'io-ts/lib/PathReporter'

assert.deepStrictEqual(IntFromString.decode('1'), right(1))
assert.deepStrictEqual(PathReporter.report(IntFromString.decode('1.1')), [
  'Invalid value "1.1" supplied to : IntFromString'
])

Added in v0.4.4