-
-
Notifications
You must be signed in to change notification settings - Fork 655
/
typeof.ts
46 lines (40 loc) · 1.27 KB
/
typeof.ts
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
assert(typeof 1 == "number");
class SomeClass {
static someStaticMethod(): void {}
someInstanceMethod(): void {}
}
enum SomeEnum {}
namespace SomeNamespace { const a: i32 = 1; }
function SomeFunction(): void {}
assert(typeof SomeClass == "object"); // ClassPrototype
assert(typeof SomeEnum == "object"); // Enum
assert(typeof SomeNamespace == "object"); // Namespace (TS complains if empty)
assert(typeof SomeFunction == "function"); // FunctionPrototype
assert(typeof SomeClass.someStaticMethod == "function");
assert(typeof true == "boolean");
assert(typeof null == "object");
assert(typeof 1 == "number");
assert(typeof 1.0 == "number");
assert(typeof <i64>1 == "number");
assert(typeof "1" == "string");
var b = true;
assert(typeof b == "boolean");
var i = 1;
assert(typeof i == "number");
var f = <f32>1.0;
assert(typeof f == "number");
var I = <i64>1;
assert(typeof I == "number");
var F = 1.0;
assert(typeof F == "number");
var s = "1";
assert(typeof s == "string");
var fn = (): void => {};
assert(typeof fn == "function");
var c = new SomeClass();
assert(typeof c == "object");
assert(typeof c.someInstanceMethod == "function");
// would normally error but doesn't with typeof:
assert(typeof d == "undefined");
assert(typeof c.ba == "undefined");
assert(typeof c[0] == "undefined");