Skip to content

Commit 2a4d267

Browse files
committed
Accept new baselines
1 parent 46bdded commit 2a4d267

4 files changed

+628
-1
lines changed

tests/baselines/reference/recursiveTypeReferences1.errors.txt

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeRefe
22
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(60,7): error TS2322: Type 'number' is not assignable to type 'string | RecArray<string>'.
33
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(66,8): error TS2322: Type 'number' is not assignable to type 'string | string[]'.
44
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(72,8): error TS2322: Type 'number' is not assignable to type 'string | (string | string[])[]'.
5+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(102,10): error TS2304: Cannot find name 'html'.
6+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(104,12): error TS2304: Cannot find name 'html'.
7+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(105,7): error TS2304: Cannot find name 'html'.
8+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(106,52): error TS2304: Cannot find name 'frag'.
9+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(116,11): error TS2304: Cannot find name 'concat'.
10+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(116,24): error TS2304: Cannot find name 'concat'.
11+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(117,11): error TS2304: Cannot find name 'concat'.
12+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(122,11): error TS2304: Cannot find name 'concat'.
13+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(127,3): error TS2304: Cannot find name 'assert'.
514

615

7-
==== tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts (4 errors) ====
16+
==== tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts (13 errors) ====
817
type ValueOrArray<T> = T | Array<ValueOrArray<T>>;
918

1019
const a0: ValueOrArray<number> = 1;
@@ -92,4 +101,72 @@ tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeRefe
92101
type T13 = T13[] | string;
93102
type T14 = T14[] & { x: string };
94103
type T15<X> = X extends string ? T15<X>[] : never;
104+
105+
type ValueOrArray1<T> = T | ValueOrArray1<T>[];
106+
type ValueOrArray2<T> = T | ValueOrArray2<T>[];
107+
108+
declare function foo1<T>(a: ValueOrArray1<T>): T;
109+
declare let ra1: ValueOrArray2<string>;
110+
111+
let x1 = foo1(ra1); // Boom!
112+
113+
type NumberOrArray1<T> = T | ValueOrArray1<T>[];
114+
type NumberOrArray2<T> = T | ValueOrArray2<T>[];
115+
116+
declare function foo2<T>(a: ValueOrArray1<T>): T;
117+
declare let ra2: ValueOrArray2<string>;
118+
119+
let x2 = foo2(ra2); // Boom!
120+
121+
// Repro from #33617 (errors are expected)
122+
123+
type Tree = [HTMLHeadingElement, Tree][];
124+
125+
function parse(node: Tree, index: number[] = []): HTMLUListElement {
126+
return html('ul', node.map(([el, children], i) => {
127+
~~~~
128+
!!! error TS2304: Cannot find name 'html'.
129+
const idx = [...index, i + 1];
130+
return html('li', [
131+
~~~~
132+
!!! error TS2304: Cannot find name 'html'.
133+
html('a', { href: `#${el.id}`, rel: 'noopener', 'data-index': idx.join('.') }, el.textContent!),
134+
~~~~
135+
!!! error TS2304: Cannot find name 'html'.
136+
children.length > 0 ? parse(children, idx) : frag()
137+
~~~~
138+
!!! error TS2304: Cannot find name 'frag'.
139+
]);
140+
}));
141+
}
142+
143+
function cons(hs: HTMLHeadingElement[]): Tree {
144+
return hs
145+
.reduce<HTMLHeadingElement[][]>((hss, h) => {
146+
const hs = hss.pop()!;
147+
return hs.length === 0 || level(h) > level(hs[0])
148+
? concat(hss, [concat(hs, [h])])
149+
~~~~~~
150+
!!! error TS2304: Cannot find name 'concat'.
151+
~~~~~~
152+
!!! error TS2304: Cannot find name 'concat'.
153+
: concat(hss, [hs, [h]]);
154+
~~~~~~
155+
!!! error TS2304: Cannot find name 'concat'.
156+
}, [[]])
157+
.reduce<Tree>((node, hs) =>
158+
hs.length === 0
159+
? node
160+
: concat<Tree[number]>(node, [[hs.shift()!, cons(hs)]])
161+
~~~~~~
162+
!!! error TS2304: Cannot find name 'concat'.
163+
, []);
164+
}
165+
166+
function level(h: HTMLHeadingElement): number {
167+
assert(isFinite(+h.tagName[1]));
168+
~~~~~~
169+
!!! error TS2304: Cannot find name 'assert'.
170+
return +h.tagName[1];
171+
}
95172

tests/baselines/reference/recursiveTypeReferences1.js

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

82132

83133
//// [recursiveTypeReferences1.js]
84134
"use strict";
135+
var __spreadArrays = (this && this.__spreadArrays) || function () {
136+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
137+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
138+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
139+
r[k] = a[j];
140+
return r;
141+
};
85142
var a0 = 1;
86143
var a1 = [1, [2, 3], [4, [5, [6, 7]]]];
87144
var hypertextNode = ["div", { id: "parent" },
@@ -124,6 +181,37 @@ flat2([[[0]]]); // number[]
124181
flat2([1, 'a', [2]]); // (string | number)[]
125182
flat2([1, [2, 'a']]); // (string | number)[]
126183
flat2([1, ['a']]); // Error
184+
var x1 = foo1(ra1); // Boom!
185+
var x2 = foo2(ra2); // Boom!
186+
function parse(node, index) {
187+
if (index === void 0) { index = []; }
188+
return html('ul', node.map(function (_a, i) {
189+
var el = _a[0], children = _a[1];
190+
var idx = __spreadArrays(index, [i + 1]);
191+
return html('li', [
192+
html('a', { href: "#" + el.id, rel: 'noopener', 'data-index': idx.join('.') }, el.textContent),
193+
children.length > 0 ? parse(children, idx) : frag()
194+
]);
195+
}));
196+
}
197+
function cons(hs) {
198+
return hs
199+
.reduce(function (hss, h) {
200+
var hs = hss.pop();
201+
return hs.length === 0 || level(h) > level(hs[0])
202+
? concat(hss, [concat(hs, [h])])
203+
: concat(hss, [hs, [h]]);
204+
}, [[]])
205+
.reduce(function (node, hs) {
206+
return hs.length === 0
207+
? node
208+
: concat(node, [[hs.shift(), cons(hs)]]);
209+
}, []);
210+
}
211+
function level(h) {
212+
assert(isFinite(+h.tagName[1]));
213+
return +h.tagName[1];
214+
}
127215

128216

129217
//// [recursiveTypeReferences1.d.ts]
@@ -165,3 +253,17 @@ declare type T14 = T14[] & {
165253
x: string;
166254
};
167255
declare type T15<X> = X extends string ? T15<X>[] : never;
256+
declare type ValueOrArray1<T> = T | ValueOrArray1<T>[];
257+
declare type ValueOrArray2<T> = T | ValueOrArray2<T>[];
258+
declare function foo1<T>(a: ValueOrArray1<T>): T;
259+
declare let ra1: ValueOrArray2<string>;
260+
declare let x1: string;
261+
declare type NumberOrArray1<T> = T | ValueOrArray1<T>[];
262+
declare type NumberOrArray2<T> = T | ValueOrArray2<T>[];
263+
declare function foo2<T>(a: ValueOrArray1<T>): T;
264+
declare let ra2: ValueOrArray2<string>;
265+
declare let x2: string;
266+
declare type Tree = [HTMLHeadingElement, Tree][];
267+
declare function parse(node: Tree, index?: number[]): HTMLUListElement;
268+
declare function cons(hs: HTMLHeadingElement[]): Tree;
269+
declare function level(h: HTMLHeadingElement): number;

0 commit comments

Comments
 (0)