File: typeGuardConstructorDerivedClass.types

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (161 lines) | stat: -rw-r--r-- 2,719 bytes parent folder | download | duplicates (4)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
=== tests/cases/compiler/typeGuardConstructorDerivedClass.ts ===
// Derived class with different structures
class C1 {
>C1 : C1

    property1: number;
>property1 : number
}

class C2 extends C1 {
>C2 : C2
>C1 : C1

    property2: number;
>property2 : number
}

let var1: C2 | string;
>var1 : string | C2

if (var1.constructor === C1) {
>var1.constructor === C1 : boolean
>var1.constructor : Function
>var1 : string | C2
>constructor : Function
>C1 : typeof C1

    var1; // never
>var1 : never

    var1.property1; // error
>var1.property1 : any
>var1 : never
>property1 : any
}
if (var1.constructor === C2) {
>var1.constructor === C2 : boolean
>var1.constructor : Function
>var1 : string | C2
>constructor : Function
>C2 : typeof C2

    var1; // C2
>var1 : C2

    var1.property1; // number
>var1.property1 : number
>var1 : C2
>property1 : number
}

// Derived classes with the same structure
class C3 {}
>C3 : C3

class C4 extends C3 {}
>C4 : C4
>C3 : C3

let var2: C4 | string;
>var2 : string | C4

if (var2.constructor === C3) {
>var2.constructor === C3 : boolean
>var2.constructor : Function
>var2 : string | C4
>constructor : Function
>C3 : typeof C3

    var2; // never
>var2 : never
}
if (var2.constructor === C4) {
>var2.constructor === C4 : boolean
>var2.constructor : Function
>var2 : string | C4
>constructor : Function
>C4 : typeof C4

    var2; // C4
>var2 : C4
}

// Disjointly structured classes
class C5 {
>C5 : C5

    property1: number;
>property1 : number
}

class C6 {
>C6 : C6

    property2: number;
>property2 : number
}

let let3: C6 | string;
>let3 : string | C6

if (let3.constructor === C5) {
>let3.constructor === C5 : boolean
>let3.constructor : Function
>let3 : string | C6
>constructor : Function
>C5 : typeof C5

    let3; // never
>let3 : never
}
if (let3.constructor === C6) {
>let3.constructor === C6 : boolean
>let3.constructor : Function
>let3 : string | C6
>constructor : Function
>C6 : typeof C6

    let3; // C6
>let3 : C6
}

// Classes with the same structure
class C7 {
>C7 : C7

    property1: number
>property1 : number
}

class C8 {
>C8 : C8

    property1: number;
>property1 : number
}

let let4: C8 | string;
>let4 : string | C8

if (let4.constructor === C7) {
>let4.constructor === C7 : boolean
>let4.constructor : Function
>let4 : string | C8
>constructor : Function
>C7 : typeof C7

    let4; // never
>let4 : never
}
if (let4.constructor === C8) {
>let4.constructor === C8 : boolean
>let4.constructor : Function
>let4 : string | C8
>constructor : Function
>C8 : typeof C8

    let4; // C8
>let4 : C8
}