Skip to content

Commit 3aa3326

Browse files
committed
Accept new baselines
1 parent e3d23cc commit 3aa3326

File tree

4 files changed

+903
-0
lines changed

4 files changed

+903
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(45,7): error TS2322: Type '42' is not assignable to type 'Box2'.
2+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(60,7): error TS2322: Type 'number' is not assignable to type 'string | RecArray<string>'.
3+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(66,8): error TS2322: Type 'number' is not assignable to type 'string | string[]'.
4+
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(72,8): error TS2322: Type 'number' is not assignable to type 'string | (string | string[])[]'.
5+
6+
7+
==== tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts (4 errors) ====
8+
type ValueOrArray<T> = T | Array<ValueOrArray<T>>;
9+
10+
const a0: ValueOrArray<number> = 1;
11+
const a1: ValueOrArray<number> = [1, [2, 3], [4, [5, [6, 7]]]];
12+
13+
type HypertextNode = string | [string, { [key: string]: unknown }, ...HypertextNode[]];
14+
15+
const hypertextNode: HypertextNode =
16+
["div", { id: "parent" },
17+
["div", { id: "first-child" }, "I'm the first child"],
18+
["div", { id: "second-child" }, "I'm the second child"]
19+
];
20+
21+
type Json = string | number | boolean | null | Json[] | { [key: string]: Json };
22+
23+
let data: Json = {
24+
caption: "Test",
25+
location: { x: 10, y: 20 },
26+
values: [true, [10, 20], null]
27+
};
28+
29+
interface Box<T> { value: T };
30+
31+
type T1 = Box<T1>;
32+
type T2 = Box<Box<T2>>;
33+
type T3 = Box<Box<Box<T3>>>;
34+
35+
function f1(t1: T1, t2: T2, t3: T3) {
36+
t1 = t2;
37+
t1 = t3;
38+
t2 = t1;
39+
t2 = t3;
40+
t3 = t1;
41+
t3 = t2;
42+
}
43+
44+
type Box1 = Box<Box1> | number;
45+
46+
const b10: Box1 = 42;
47+
const b11: Box1 = { value: 42 };
48+
const b12: Box1 = { value: { value: { value: 42 }}};
49+
50+
type Box2 = Box<Box2 | number>;
51+
52+
const b20: Box2 = 42; // Error
53+
~~~
54+
!!! error TS2322: Type '42' is not assignable to type 'Box2'.
55+
const b21: Box2 = { value: 42 };
56+
const b22: Box2 = { value: { value: { value: 42 }}};
57+
58+
type RecArray<T> = Array<T | RecArray<T>>;
59+
60+
declare function flat<T>(a: RecArray<T>): Array<T>;
61+
declare function flat1<T>(a: Array<T | Array<T>>): Array<T>
62+
declare function flat2<T>(a: Array<T | Array<T | Array<T>>>): Array<T>;
63+
64+
flat([1, [2, [3]]]); // number[]
65+
flat([[[0]]]); // number[]
66+
flat([[[[[[[[[[[4]]]]]]]]]]]); // number[]
67+
flat([1, 'a', [2]]); // (string | number)[]
68+
flat([1, [2, 'a']]); // (string | number)[]
69+
flat([1, ['a']]); // Error
70+
~
71+
!!! error TS2322: Type 'number' is not assignable to type 'string | RecArray<string>'.
72+
73+
flat1([1, [2, [3]]]); // (number | number[])[]
74+
flat1([[[0]]]); // number[][]
75+
flat1([1, 'a', [2]]); // (string | number)[]
76+
flat1([1, [2, 'a']]); // (string | number)[]
77+
flat1([1, ['a']]); // Error
78+
~
79+
!!! error TS2322: Type 'number' is not assignable to type 'string | string[]'.
80+
81+
flat2([1, [2, [3]]]); // number[]
82+
flat2([[[0]]]); // number[]
83+
flat2([1, 'a', [2]]); // (string | number)[]
84+
flat2([1, [2, 'a']]); // (string | number)[]
85+
flat2([1, ['a']]); // Error
86+
~
87+
!!! error TS2322: Type 'number' is not assignable to type 'string | (string | string[])[]'.
88+
89+
type T10 = T10[];
90+
type T11 = readonly T11[];
91+
type T12 = (T12)[];
92+
type T13 = T13[] | string;
93+
type T14 = T14[] & { x: string };
94+
type T15<X> = X extends string ? T15<X>[] : never;
95+
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
//// [recursiveTypeReferences1.ts]
2+
type ValueOrArray<T> = T | Array<ValueOrArray<T>>;
3+
4+
const a0: ValueOrArray<number> = 1;
5+
const a1: ValueOrArray<number> = [1, [2, 3], [4, [5, [6, 7]]]];
6+
7+
type HypertextNode = string | [string, { [key: string]: unknown }, ...HypertextNode[]];
8+
9+
const hypertextNode: HypertextNode =
10+
["div", { id: "parent" },
11+
["div", { id: "first-child" }, "I'm the first child"],
12+
["div", { id: "second-child" }, "I'm the second child"]
13+
];
14+
15+
type Json = string | number | boolean | null | Json[] | { [key: string]: Json };
16+
17+
let data: Json = {
18+
caption: "Test",
19+
location: { x: 10, y: 20 },
20+
values: [true, [10, 20], null]
21+
};
22+
23+
interface Box<T> { value: T };
24+
25+
type T1 = Box<T1>;
26+
type T2 = Box<Box<T2>>;
27+
type T3 = Box<Box<Box<T3>>>;
28+
29+
function f1(t1: T1, t2: T2, t3: T3) {
30+
t1 = t2;
31+
t1 = t3;
32+
t2 = t1;
33+
t2 = t3;
34+
t3 = t1;
35+
t3 = t2;
36+
}
37+
38+
type Box1 = Box<Box1> | number;
39+
40+
const b10: Box1 = 42;
41+
const b11: Box1 = { value: 42 };
42+
const b12: Box1 = { value: { value: { value: 42 }}};
43+
44+
type Box2 = Box<Box2 | number>;
45+
46+
const b20: Box2 = 42; // Error
47+
const b21: Box2 = { value: 42 };
48+
const b22: Box2 = { value: { value: { value: 42 }}};
49+
50+
type RecArray<T> = Array<T | RecArray<T>>;
51+
52+
declare function flat<T>(a: RecArray<T>): Array<T>;
53+
declare function flat1<T>(a: Array<T | Array<T>>): Array<T>
54+
declare function flat2<T>(a: Array<T | Array<T | Array<T>>>): Array<T>;
55+
56+
flat([1, [2, [3]]]); // number[]
57+
flat([[[0]]]); // number[]
58+
flat([[[[[[[[[[[4]]]]]]]]]]]); // number[]
59+
flat([1, 'a', [2]]); // (string | number)[]
60+
flat([1, [2, 'a']]); // (string | number)[]
61+
flat([1, ['a']]); // Error
62+
63+
flat1([1, [2, [3]]]); // (number | number[])[]
64+
flat1([[[0]]]); // number[][]
65+
flat1([1, 'a', [2]]); // (string | number)[]
66+
flat1([1, [2, 'a']]); // (string | number)[]
67+
flat1([1, ['a']]); // Error
68+
69+
flat2([1, [2, [3]]]); // number[]
70+
flat2([[[0]]]); // number[]
71+
flat2([1, 'a', [2]]); // (string | number)[]
72+
flat2([1, [2, 'a']]); // (string | number)[]
73+
flat2([1, ['a']]); // Error
74+
75+
type T10 = T10[];
76+
type T11 = readonly T11[];
77+
type T12 = (T12)[];
78+
type T13 = T13[] | string;
79+
type T14 = T14[] & { x: string };
80+
type T15<X> = X extends string ? T15<X>[] : never;
81+
82+
83+
//// [recursiveTypeReferences1.js]
84+
"use strict";
85+
var a0 = 1;
86+
var a1 = [1, [2, 3], [4, [5, [6, 7]]]];
87+
var hypertextNode = ["div", { id: "parent" },
88+
["div", { id: "first-child" }, "I'm the first child"],
89+
["div", { id: "second-child" }, "I'm the second child"]
90+
];
91+
var data = {
92+
caption: "Test",
93+
location: { x: 10, y: 20 },
94+
values: [true, [10, 20], null]
95+
};
96+
;
97+
function f1(t1, t2, t3) {
98+
t1 = t2;
99+
t1 = t3;
100+
t2 = t1;
101+
t2 = t3;
102+
t3 = t1;
103+
t3 = t2;
104+
}
105+
var b10 = 42;
106+
var b11 = { value: 42 };
107+
var b12 = { value: { value: { value: 42 } } };
108+
var b20 = 42; // Error
109+
var b21 = { value: 42 };
110+
var b22 = { value: { value: { value: 42 } } };
111+
flat([1, [2, [3]]]); // number[]
112+
flat([[[0]]]); // number[]
113+
flat([[[[[[[[[[[4]]]]]]]]]]]); // number[]
114+
flat([1, 'a', [2]]); // (string | number)[]
115+
flat([1, [2, 'a']]); // (string | number)[]
116+
flat([1, ['a']]); // Error
117+
flat1([1, [2, [3]]]); // (number | number[])[]
118+
flat1([[[0]]]); // number[][]
119+
flat1([1, 'a', [2]]); // (string | number)[]
120+
flat1([1, [2, 'a']]); // (string | number)[]
121+
flat1([1, ['a']]); // Error
122+
flat2([1, [2, [3]]]); // number[]
123+
flat2([[[0]]]); // number[]
124+
flat2([1, 'a', [2]]); // (string | number)[]
125+
flat2([1, [2, 'a']]); // (string | number)[]
126+
flat2([1, ['a']]); // Error
127+
128+
129+
//// [recursiveTypeReferences1.d.ts]
130+
declare type ValueOrArray<T> = T | Array<ValueOrArray<T>>;
131+
declare const a0: ValueOrArray<number>;
132+
declare const a1: ValueOrArray<number>;
133+
declare type HypertextNode = string | [string, {
134+
[key: string]: unknown;
135+
}, ...HypertextNode[]];
136+
declare const hypertextNode: HypertextNode;
137+
declare type Json = string | number | boolean | null | Json[] | {
138+
[key: string]: Json;
139+
};
140+
declare let data: Json;
141+
interface Box<T> {
142+
value: T;
143+
}
144+
declare type T1 = Box<T1>;
145+
declare type T2 = Box<Box<T2>>;
146+
declare type T3 = Box<Box<Box<T3>>>;
147+
declare function f1(t1: T1, t2: T2, t3: T3): void;
148+
declare type Box1 = Box<Box1> | number;
149+
declare const b10: Box1;
150+
declare const b11: Box1;
151+
declare const b12: Box1;
152+
declare type Box2 = Box<Box2 | number>;
153+
declare const b20: Box2;
154+
declare const b21: Box2;
155+
declare const b22: Box2;
156+
declare type RecArray<T> = Array<T | RecArray<T>>;
157+
declare function flat<T>(a: RecArray<T>): Array<T>;
158+
declare function flat1<T>(a: Array<T | Array<T>>): Array<T>;
159+
declare function flat2<T>(a: Array<T | Array<T | Array<T>>>): Array<T>;
160+
declare type T10 = T10[];
161+
declare type T11 = readonly T11[];
162+
declare type T12 = (T12)[];
163+
declare type T13 = T13[] | string;
164+
declare type T14 = T14[] & {
165+
x: string;
166+
};
167+
declare type T15<X> = X extends string ? T15<X>[] : never;

0 commit comments

Comments
 (0)