File: recursiveTypesWithTypeof.js

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (98 lines) | stat: -rw-r--r-- 2,109 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//// [recursiveTypesWithTypeof.ts]
// The following are errors because of circular references
var c: typeof c;
var c: any;
var d: typeof e;
var d: any;
var e: typeof d;
var e: any;

interface Foo<T> { }
var f: Array<typeof f>;
var f: any;
var f2: Foo<typeof f2>;
var f2: any;
var f3: Foo<typeof f3>[];
var f3: any;

// None of these declarations should have any errors!
// Truly recursive types
var g: { x: typeof g; };
var g: typeof g.x;
var h: () => typeof h;
var h = h();
var i: (x: typeof i) => typeof x;
var i = i(i);
var j: <T extends typeof j>(x: T) => T;
var j = j(j);

// Same as h, i, j with construct signatures
var h2: new () => typeof h2;
var h2 = new h2();
var i2: new (x: typeof i2) => typeof x;
var i2 = new i2(i2);
var j2: new <T extends typeof j2>(x: T) => T;
var j2 = new j2(j2);

// Indexers
var k: { [n: number]: typeof k;[s: string]: typeof k };
var k = k[0];
var k = k[''];

// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1: { x: typeof hy1 }[];
var hy1 = hy1[0].x;
var hy2: { x: Array<typeof hy2> };
var hy2 = hy2.x[0];

interface Foo2<T, U> { }

// This one should be an error because the first type argument is not contained inside a type literal
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
var hy3: any;

//// [recursiveTypesWithTypeof.js]
// The following are errors because of circular references
var c;
var c;
var d;
var d;
var e;
var e;
var f;
var f;
var f2;
var f2;
var f3;
var f3;
// None of these declarations should have any errors!
// Truly recursive types
var g;
var g;
var h;
var h = h();
var i;
var i = i(i);
var j;
var j = j(j);
// Same as h, i, j with construct signatures
var h2;
var h2 = new h2();
var i2;
var i2 = new i2(i2);
var j2;
var j2 = new j2(j2);
// Indexers
var k;
var k = k[0];
var k = k[''];
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1;
var hy1 = hy1[0].x;
var hy2;
var hy2 = hy2.x[0];
// This one should be an error because the first type argument is not contained inside a type literal
var hy3;
var hy3;