File: typeofOperatorWithStringType.types

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 (233 lines) | stat: -rw-r--r-- 8,315 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
=== tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithStringType.ts ===
// typeof  operator on string type
var STRING: string;
>STRING : string

var STRING1: string[] = ["", "abc"];
>STRING1 : string[]
>["", "abc"] : string[]
>"" : ""
>"abc" : "abc"

function foo(): string { return "abc"; }
>foo : () => string
>"abc" : "abc"

class A {
>A : A

    public a: string;
>a : string

    static foo() { return ""; }
>foo : () => string
>"" : ""
}
module M {
>M : typeof M

    export var n: string;
>n : string
}

var objA = new A();
>objA : A
>new A() : A
>A : typeof A

// string type var
var ResultIsString1 = typeof STRING;
>ResultIsString1 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof STRING : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>STRING : string

var ResultIsString2 = typeof STRING1;
>ResultIsString2 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof STRING1 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>STRING1 : string[]

// string type literal
var ResultIsString3 = typeof "";
>ResultIsString3 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof "" : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>"" : ""

var ResultIsString4 = typeof { x: "", y: "" };
>ResultIsString4 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof { x: "", y: "" } : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>{ x: "", y: "" } : { x: string; y: string; }
>x : string
>"" : ""
>y : string
>"" : ""

var ResultIsString5 = typeof { x: "", y: (s: string) => { return s; } };
>ResultIsString5 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof { x: "", y: (s: string) => { return s; } } : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>{ x: "", y: (s: string) => { return s; } } : { x: string; y: (s: string) => string; }
>x : string
>"" : ""
>y : (s: string) => string
>(s: string) => { return s; } : (s: string) => string
>s : string
>s : string

// string type expressions
var ResultIsString6 = typeof objA.a;
>ResultIsString6 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof objA.a : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>objA.a : string
>objA : A
>a : string

var ResultIsString7 = typeof M.n;
>ResultIsString7 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof M.n : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>M.n : string
>M : typeof M
>n : string

var ResultIsString8 = typeof STRING1[0];
>ResultIsString8 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof STRING1[0] : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>STRING1[0] : string
>STRING1 : string[]
>0 : 0

var ResultIsString9 = typeof foo();
>ResultIsString9 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof foo() : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>foo() : string
>foo : () => string

var ResultIsString10 = typeof A.foo();
>ResultIsString10 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof A.foo() : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>A.foo() : string
>A.foo : () => string
>A : typeof A
>foo : () => string

var ResultIsString11 = typeof (STRING + STRING);
>ResultIsString11 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof (STRING + STRING) : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>(STRING + STRING) : string
>STRING + STRING : string
>STRING : string
>STRING : string

var ResultIsString12 = typeof STRING.charAt(0);
>ResultIsString12 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof STRING.charAt(0) : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>STRING.charAt(0) : string
>STRING.charAt : (pos: number) => string
>STRING : string
>charAt : (pos: number) => string
>0 : 0

// multiple typeof  operators
var ResultIsString13 = typeof typeof STRING;
>ResultIsString13 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof typeof STRING : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof STRING : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>STRING : string

var ResultIsString14 = typeof typeof typeof (STRING + STRING);
>ResultIsString14 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof typeof typeof (STRING + STRING) : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof typeof (STRING + STRING) : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>typeof (STRING + STRING) : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>(STRING + STRING) : string
>STRING + STRING : string
>STRING : string
>STRING : string

// miss assignment operators
typeof "";
>typeof "" : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>"" : ""

typeof STRING;
>typeof STRING : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>STRING : string

typeof STRING1;
>typeof STRING1 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>STRING1 : string[]

typeof foo();
>typeof foo() : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>foo() : string
>foo : () => string

typeof objA.a, M.n;
>typeof objA.a, M.n : string
>typeof objA.a : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>objA.a : string
>objA : A
>a : string
>M.n : string
>M : typeof M
>n : string

// use typeof in type query
var z: string;
>z : string

var x: string[];
>x : string[]

var r: () => string;
>r : () => string

z: typeof STRING;
>z : any
>typeof STRING : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>STRING : string

x: typeof STRING1;
>x : any
>typeof STRING1 : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>STRING1 : string[]

r: typeof foo;
>r : any
>typeof foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>foo : () => string

var y = { a: "", b: "" };
>y : { a: string; b: string; }
>{ a: "", b: "" } : { a: string; b: string; }
>a : string
>"" : ""
>b : string
>"" : ""

z: typeof y.a;
>z : any
>typeof y.a : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>y.a : string
>y : { a: string; b: string; }
>a : string

z: typeof objA.a;
>z : any
>typeof objA.a : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>objA.a : string
>objA : A
>a : string

z: typeof A.foo;
>z : any
>typeof A.foo : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>A.foo : () => string
>A : typeof A
>foo : () => string

z: typeof M.n;
>z : any
>typeof M.n : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>M.n : string
>M : typeof M
>n : string