@@ -10,70 +10,88 @@ export function main(): void {
10
10
let ch4 = $ . makeChannel < { } > ( 0 , { } , 'both' )
11
11
12
12
let i : null | any = ch1
13
- { let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'both' } )
13
+ {
14
+ let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'both' } )
14
15
if ( ok ) {
15
16
console . log ( "i is chan int: ok" )
16
17
} else {
17
18
console . log ( "i is chan int: failed" )
18
19
}
19
20
}
21
+
20
22
let s : null | any = ch2
21
- { let { ok : ok } = $ . typeAssert < $ . Channel < string > > ( s , { kind : $ . TypeKind . Channel , elemType : 'string' , direction : 'send' } )
23
+ {
24
+ let { ok : ok } = $ . typeAssert < $ . Channel < string > > ( s , { kind : $ . TypeKind . Channel , elemType : 'string' , direction : 'send' } )
22
25
if ( ok ) {
23
26
console . log ( "s is chan<- string: ok" )
24
27
} else {
25
28
console . log ( "s is chan<- string: failed" )
26
29
}
27
30
}
31
+
28
32
let r : null | any = ch3
29
- { let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( r , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'receive' } )
33
+ {
34
+ let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( r , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'receive' } )
30
35
if ( ok ) {
31
36
console . log ( "r is <-chan float64: ok" )
32
37
} else {
33
38
console . log ( "r is <-chan float64: failed" )
34
39
}
35
40
}
41
+
36
42
let e : null | any = ch4
37
- { let { ok : ok } = $ . typeAssert < $ . Channel < { } > > ( e , { kind : $ . TypeKind . Channel , elemType : { kind : $ . TypeKind . Struct , fields : { } , methods : [ ] } , direction : 'both' } )
43
+ {
44
+ let { ok : ok } = $ . typeAssert < $ . Channel < { } > > ( e , { kind : $ . TypeKind . Channel , elemType : { kind : $ . TypeKind . Struct , fields : { } , methods : [ ] } , direction : 'both' } )
38
45
if ( ok ) {
39
46
console . log ( "e is chan struct{}: ok" )
40
47
} else {
41
48
console . log ( "e is chan struct{}: failed" )
42
49
}
43
50
}
44
- { let { ok : ok } = $ . typeAssert < $ . Channel < string > > ( i , { kind : $ . TypeKind . Channel , elemType : 'string' , direction : 'both' } )
51
+
52
+ {
53
+ let { ok : ok } = $ . typeAssert < $ . Channel < string > > ( i , { kind : $ . TypeKind . Channel , elemType : 'string' , direction : 'both' } )
45
54
if ( ok ) {
46
55
console . log ( "i is chan string: incorrect" )
47
56
} else {
48
57
console . log ( "i is chan string: correctly failed" )
49
58
}
50
59
}
51
- { let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'send' } )
60
+
61
+ {
62
+ let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'send' } )
52
63
if ( ok ) {
53
64
console . log ( "i is chan<- int: incorrect" )
54
65
} else {
55
66
console . log ( "i is chan<- int: correctly failed" )
56
67
}
57
68
}
58
- { let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'receive' } )
69
+
70
+ {
71
+ let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'receive' } )
59
72
if ( ok ) {
60
73
console . log ( "i is <-chan int: incorrect" )
61
74
} else {
62
75
console . log ( "i is <-chan int: correctly failed" )
63
76
}
64
77
}
65
- { let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'send' } )
78
+
79
+ {
80
+ let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'send' } )
66
81
if ( ok ) {
67
82
console . log ( "bidirectional can be used as send-only: ok" )
68
83
} else {
69
84
console . log ( "bidirectional can be used as send-only: failed" )
70
85
}
71
86
}
72
- { let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'receive' } )
87
+
88
+ {
89
+ let { ok : ok } = $ . typeAssert < $ . Channel < number > > ( i , { kind : $ . TypeKind . Channel , elemType : 'number' , direction : 'receive' } )
73
90
if ( ok ) {
74
91
console . log ( "bidirectional can be used as receive-only: ok" )
75
92
} else {
76
93
console . log ( "bidirectional can be used as receive-only: failed" )
77
94
}
78
- } }
95
+ }
96
+ }
79
97
0 commit comments