File: subtypesOfUnion.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 (82 lines) | stat: -rw-r--r-- 1,941 bytes parent folder | download | duplicates (5)
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
//// [subtypesOfUnion.ts]
enum E { e1, e2 }
interface I8 { [x: string]: number[]; }
class A { foo: number; }
class A2<T> { foo: T; }
function f() { }
module f { export var bar = 1; }
class c { baz: string }
module c { export var bar = 1; }

// A type T is a subtype of a union type U if T is a subtype of any type in U.
interface I1<T> {
    [x: string]: string | number;
    foo: any; // ok
    foo2: string; // ok
    foo3: number; // ok
    foo4: boolean; // error 
    foo5: E; // ok - subtype of number 
    foo6: Date; // error
    foo7: RegExp; // error
    foo8: { bar: number }; // error
    foo9: I8; // error
    foo10: A; // error
    foo11: A2<number>; // error
    foo12: (x) => number; //error
    foo13: <T>(x: T) => T; // error
    foo14: typeof f; // error
    foo15: typeof c; // error
    foo16: T; // error
    foo17: Object; // error
    foo18: {}; // error
}
interface I2<T> {
    [x: string]: E | number;
    foo: any; // ok
    foo2: string; // error
    foo3: number; // ok
    foo4: boolean; // error 
    foo5: E; // ok
    foo6: Date; // error
    foo7: RegExp; // error
    foo8: { bar: number }; // error
    foo9: I8; // error
    foo10: A; // error
    foo11: A2<number>; // error
    foo12: (x) => number; //error
    foo13: <T>(x: T) => T; // error
    foo14: typeof f; // error
    foo15: typeof c; // error
    foo16: T; // error
    foo17: Object; // error
    foo18: {}; // error
}

//// [subtypesOfUnion.js]
var E;
(function (E) {
    E[E["e1"] = 0] = "e1";
    E[E["e2"] = 1] = "e2";
})(E || (E = {}));
var A = /** @class */ (function () {
    function A() {
    }
    return A;
}());
var A2 = /** @class */ (function () {
    function A2() {
    }
    return A2;
}());
function f() { }
(function (f) {
    f.bar = 1;
})(f || (f = {}));
var c = /** @class */ (function () {
    function c() {
    }
    return c;
}());
(function (c) {
    c.bar = 1;
})(c || (c = {}));