1 | /**
|
2 | * @since 0.5.0
|
3 | */
|
4 | import { Option } from 'fp-ts/lib/Option'
|
5 | import * as t from 'io-ts'
|
6 | declare const None: t.ExactC<
|
7 | t.TypeC<{
|
8 | _tag: t.LiteralC<'None'>
|
9 | }>
|
10 | >
|
11 | /**
|
12 | * @since 0.5.18
|
13 | */
|
14 | export declare type NoneOutput = t.OutputOf<typeof None>
|
15 | /**
|
16 | * @since 0.5.18
|
17 | */
|
18 | export declare type SomeOutput<A> = {
|
19 | _tag: 'Some'
|
20 | value: A
|
21 | }
|
22 | /**
|
23 | * @since 0.5.18
|
24 | */
|
25 | export declare type OptionOutput<A> = NoneOutput | SomeOutput<A>
|
26 | /**
|
27 | * Given a codec representing a type `A`, returns a codec representing `Option<A>` that is able to deserialize
|
28 | * the JSON representation of an `Option`.
|
29 | *
|
30 | * @example
|
31 | * import { option } from 'io-ts-types/lib/option'
|
32 | * import { right } from 'fp-ts/lib/Either'
|
33 | * import { none, some } from 'fp-ts/lib/Option'
|
34 | * import * as t from 'io-ts'
|
35 | * import { PathReporter } from 'io-ts/lib/PathReporter'
|
36 | *
|
37 | * const T = option(t.number)
|
38 | *
|
39 | * assert.deepStrictEqual(T.decode(none), right(none))
|
40 | * assert.deepStrictEqual(T.decode(some(1)), right(some(1)))
|
41 | * assert.deepStrictEqual(PathReporter.report(T.decode(some('a'))), ['Invalid value "a" supplied to : Option<number>/1: Some<number>/value: number'])
|
42 | *
|
43 | * @since 0.5.0
|
44 | */
|
45 | export interface OptionC<C extends t.Mixed> extends t.Type<Option<t.TypeOf<C>>, OptionOutput<t.OutputOf<C>>, unknown> {}
|
46 | /**
|
47 | * @since 0.5.0
|
48 | */
|
49 | export declare function option<C extends t.Mixed>(codec: C, name?: string): OptionC<C>
|
50 | export {}
|