@@ -2,12 +2,14 @@ import * as assert from 'assert'
2
2
import * as t from '../src/index'
3
3
import { assertFailure , assertStrictEqual , assertSuccess , NumberFromString } from './helpers'
4
4
5
+ // tslint:disable-next-line: deprecation
5
6
const OptionNumber = t . taggedUnion (
6
7
'type' ,
7
8
[ t . type ( { type : t . literal ( 'None' ) } , 'None' ) , t . type ( { type : t . literal ( 'Some' ) , value : t . number } , 'Some' ) ] ,
8
9
'OptionNumber'
9
10
)
10
11
12
+ // tslint:disable-next-line: deprecation
11
13
const OptionNumberFromString = t . taggedUnion (
12
14
'type' ,
13
15
[ t . type ( { type : t . literal ( 'None' ) } , 'None' ) , t . type ( { type : t . literal ( 'Some' ) , value : NumberFromString } , 'Some' ) ] ,
@@ -17,6 +19,7 @@ const OptionNumberFromString = t.taggedUnion(
17
19
describe ( 'taggedUnion' , ( ) => {
18
20
describe ( 'name' , ( ) => {
19
21
it ( 'should assign a default name' , ( ) => {
22
+ // tslint:disable-next-line: deprecation
20
23
const OptionNumber = t . taggedUnion ( 'type' , [
21
24
t . type ( { type : t . literal ( 'None' ) } ) ,
22
25
t . type ( { type : t . literal ( 'Some' ) , value : t . number } )
@@ -25,6 +28,7 @@ describe('taggedUnion', () => {
25
28
} )
26
29
27
30
it ( 'should accept a name' , ( ) => {
31
+ // tslint:disable-next-line: deprecation
28
32
const T = t . taggedUnion ( 'type' , OptionNumber . types , 'T' )
29
33
assert . strictEqual ( T . name , 'T' )
30
34
} )
@@ -56,6 +60,7 @@ describe('taggedUnion', () => {
56
60
it ( 'should handle intersections' , ( ) => {
57
61
const A = t . intersection ( [ t . type ( { type : t . literal ( 'A' ) } ) , t . partial ( { a : t . string } ) ] , 'A' )
58
62
const B = t . type ( { type : t . literal ( 'B' ) , b : t . number } , 'B' )
63
+ // tslint:disable-next-line: deprecation
59
64
const T = t . taggedUnion ( 'type' , [ A , B ] , 'T' )
60
65
assertSuccess ( T . decode ( { type : 'A' } ) )
61
66
assertSuccess ( T . decode ( { type : 'B' , b : 1 } ) )
@@ -74,6 +79,7 @@ describe('taggedUnion', () => {
74
79
forest : t . array ( Self )
75
80
} )
76
81
)
82
+ // tslint:disable-next-line: deprecation
77
83
const T = t . taggedUnion ( 'type' , [ A , B ] , 'T' )
78
84
assertSuccess ( T . decode ( { type : 'A' } ) )
79
85
assertSuccess ( T . decode ( { type : 'B' , forest : [ ] } ) )
@@ -88,6 +94,7 @@ describe('taggedUnion', () => {
88
94
const B = t . type ( { type : t . literal ( 'B' ) , b : t . string } , 'B' )
89
95
const C = t . type ( { type : t . literal ( 'C' ) } , 'C' )
90
96
const SubUnion = t . union ( [ A , B ] , 'Subunion' )
97
+ // tslint:disable-next-line: deprecation
91
98
const T = t . taggedUnion ( 'type' , [ SubUnion , C ] , 'T' )
92
99
assertSuccess ( T . decode ( { type : 'A' } ) )
93
100
assertSuccess ( T . decode ( { type : 'B' , b : 'b' } ) )
@@ -99,7 +106,9 @@ describe('taggedUnion', () => {
99
106
const A = t . type ( { type : t . literal ( 'A' ) } )
100
107
const B = t . type ( { type : t . literal ( 'B' ) } )
101
108
const C = t . type ( { type : t . literal ( 'C' ) } )
109
+ // tslint:disable-next-line: deprecation
102
110
const SubTaggedUnion = t . taggedUnion ( 'type' , [ A , B ] )
111
+ // tslint:disable-next-line: deprecation
103
112
const T = t . taggedUnion ( 'type' , [ SubTaggedUnion , C ] )
104
113
assertSuccess ( T . decode ( { type : 'A' } ) )
105
114
assertSuccess ( T . decode ( { type : 'B' } ) )
@@ -112,6 +121,7 @@ describe('taggedUnion', () => {
112
121
} )
113
122
114
123
it ( 'should support numeric tags' , ( ) => {
124
+ // tslint:disable-next-line: deprecation
115
125
const T = t . taggedUnion ( 'type' , [
116
126
t . type ( { type : t . literal ( 1 ) , a : t . string } ) ,
117
127
t . type ( { type : t . literal ( 2 ) , b : t . number } )
@@ -126,6 +136,7 @@ describe('taggedUnion', () => {
126
136
} )
127
137
128
138
it ( 'should support boolean tags' , ( ) => {
139
+ // tslint:disable-next-line: deprecation
129
140
const T = t . taggedUnion ( 'type' , [
130
141
t . type ( { type : t . literal ( true ) , a : t . string } ) ,
131
142
t . type ( { type : t . literal ( false ) , b : t . number } )
@@ -140,6 +151,7 @@ describe('taggedUnion', () => {
140
151
} )
141
152
142
153
it ( 'should support mixed string, numeric and boolean tags' , ( ) => {
154
+ // tslint:disable-next-line: deprecation
143
155
const T = t . taggedUnion (
144
156
'type' ,
145
157
[
@@ -181,6 +193,7 @@ describe('taggedUnion', () => {
181
193
} )
182
194
183
195
it ( 'should handle one codec' , ( ) => {
196
+ // tslint:disable-next-line: deprecation
184
197
const T = t . taggedUnion ( 'type' , [ t . type ( { type : t . literal ( 'A' ) } ) ] as any )
185
198
assertSuccess ( T . decode ( { type : 'A' } ) )
186
199
assertFailure ( T , null , [ 'Invalid value null supplied to : ({ type: "A" })' ] )
@@ -190,6 +203,7 @@ describe('taggedUnion', () => {
190
203
const log : Array < string > = [ ]
191
204
const original = console . warn
192
205
console . warn = ( message : string ) => log . push ( message )
206
+ // tslint:disable-next-line: deprecation
193
207
t . taggedUnion ( 'type' , [ t . type ( { type : t . literal ( 'a' ) } ) , t . type ( { bad : t . literal ( 'b' ) } ) ] )
194
208
console . warn = original
195
209
assert . deepStrictEqual ( log , [
0 commit comments