@@ -80,3 +80,53 @@ type T12 = (T12)[];
80
80
type T13 = T13 [ ] | string ;
81
81
type T14 = T14 [ ] & { x : string } ;
82
82
type T15 < X > = X extends string ? T15 < X > [ ] : never ;
83
+
84
+ type ValueOrArray1 < T > = T | ValueOrArray1 < T > [ ] ;
85
+ type ValueOrArray2 < T > = T | ValueOrArray2 < T > [ ] ;
86
+
87
+ declare function foo1 < T > ( a : ValueOrArray1 < T > ) : T ;
88
+ declare let ra1 : ValueOrArray2 < string > ;
89
+
90
+ let x1 = foo1 ( ra1 ) ; // Boom!
91
+
92
+ type NumberOrArray1 < T > = T | ValueOrArray1 < T > [ ] ;
93
+ type NumberOrArray2 < T > = T | ValueOrArray2 < T > [ ] ;
94
+
95
+ declare function foo2 < T > ( a : ValueOrArray1 < T > ) : T ;
96
+ declare let ra2 : ValueOrArray2 < string > ;
97
+
98
+ let x2 = foo2 ( ra2 ) ; // Boom!
99
+
100
+ // Repro from #33617 (errors are expected)
101
+
102
+ type Tree = [ HTMLHeadingElement , Tree ] [ ] ;
103
+
104
+ function parse ( node : Tree , index : number [ ] = [ ] ) : HTMLUListElement {
105
+ return html ( 'ul' , node . map ( ( [ el , children ] , i ) => {
106
+ const idx = [ ...index , i + 1 ] ;
107
+ return html ( 'li' , [
108
+ html ( 'a' , { href : `#${ el . id } ` , rel : 'noopener' , 'data-index' : idx . join ( '.' ) } , el . textContent ! ) ,
109
+ children . length > 0 ? parse ( children , idx ) : frag ( )
110
+ ] ) ;
111
+ } ) ) ;
112
+ }
113
+
114
+ function cons ( hs : HTMLHeadingElement [ ] ) : Tree {
115
+ return hs
116
+ . reduce < HTMLHeadingElement [ ] [ ] > ( ( hss , h ) => {
117
+ const hs = hss . pop ( ) ! ;
118
+ return hs . length === 0 || level ( h ) > level ( hs [ 0 ] )
119
+ ? concat ( hss , [ concat ( hs , [ h ] ) ] )
120
+ : concat ( hss , [ hs , [ h ] ] ) ;
121
+ } , [ [ ] ] )
122
+ . reduce < Tree > ( ( node , hs ) =>
123
+ hs . length === 0
124
+ ? node
125
+ : concat < Tree [ number ] > ( node , [ [ hs . shift ( ) ! , cons ( hs ) ] ] )
126
+ , [ ] ) ;
127
+ }
128
+
129
+ function level ( h : HTMLHeadingElement ) : number {
130
+ assert ( isFinite ( + h . tagName [ 1 ] ) ) ;
131
+ return + h . tagName [ 1 ] ;
132
+ }
0 commit comments