2014-07-13 01:04:16 +02:00
|
|
|
//// [typeofOperatorWithBooleanType.ts]
|
|
|
|
// typeof operator on boolean type
|
|
|
|
var BOOLEAN: boolean;
|
|
|
|
|
|
|
|
function foo(): boolean { return true; }
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public a: boolean;
|
|
|
|
static foo() { return false; }
|
|
|
|
}
|
|
|
|
module M {
|
|
|
|
export var n: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
var objA = new A();
|
|
|
|
|
|
|
|
// boolean type var
|
|
|
|
var ResultIsString1 = typeof BOOLEAN;
|
|
|
|
|
|
|
|
// boolean type literal
|
|
|
|
var ResultIsString2 = typeof true;
|
|
|
|
var ResultIsString3 = typeof { x: true, y: false };
|
|
|
|
|
|
|
|
// boolean type expressions
|
|
|
|
var ResultIsString4 = typeof objA.a;
|
|
|
|
var ResultIsString5 = typeof M.n;
|
|
|
|
var ResultIsString6 = typeof foo();
|
|
|
|
var ResultIsString7 = typeof A.foo();
|
|
|
|
|
|
|
|
// multiple typeof operator
|
|
|
|
var ResultIsString8 = typeof typeof BOOLEAN;
|
|
|
|
|
|
|
|
// miss assignment operators
|
|
|
|
typeof true;
|
|
|
|
typeof BOOLEAN;
|
|
|
|
typeof foo();
|
|
|
|
typeof true, false;
|
|
|
|
typeof objA.a;
|
|
|
|
typeof M.n;
|
|
|
|
|
|
|
|
// use typeof in type query
|
|
|
|
var z: boolean;
|
|
|
|
var x: boolean[];
|
|
|
|
var r: () => boolean;
|
|
|
|
z: typeof BOOLEAN;
|
|
|
|
r: typeof foo;
|
|
|
|
var y = { a: true, b: false};
|
|
|
|
z: typeof y.a;
|
|
|
|
z: typeof objA.a;
|
|
|
|
z: typeof A.foo;
|
|
|
|
z: typeof M.n;
|
|
|
|
|
|
|
|
//// [typeofOperatorWithBooleanType.js]
|
2014-08-12 00:54:12 +02:00
|
|
|
// typeof operator on boolean type
|
2014-07-13 01:04:16 +02:00
|
|
|
var BOOLEAN;
|
|
|
|
function foo() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
var A = (function () {
|
|
|
|
function A() {
|
|
|
|
}
|
|
|
|
A.foo = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
return A;
|
|
|
|
})();
|
|
|
|
var M;
|
|
|
|
(function (M) {
|
|
|
|
M.n;
|
|
|
|
})(M || (M = {}));
|
|
|
|
var objA = new A();
|
2014-08-12 00:54:12 +02:00
|
|
|
// boolean type var
|
2014-07-13 01:04:16 +02:00
|
|
|
var ResultIsString1 = typeof BOOLEAN;
|
2014-08-12 00:54:12 +02:00
|
|
|
// boolean type literal
|
2014-07-13 01:04:16 +02:00
|
|
|
var ResultIsString2 = typeof true;
|
|
|
|
var ResultIsString3 = typeof { x: true, y: false };
|
2014-08-12 00:54:12 +02:00
|
|
|
// boolean type expressions
|
2014-07-13 01:04:16 +02:00
|
|
|
var ResultIsString4 = typeof objA.a;
|
|
|
|
var ResultIsString5 = typeof M.n;
|
|
|
|
var ResultIsString6 = typeof foo();
|
|
|
|
var ResultIsString7 = typeof A.foo();
|
2014-08-12 00:54:12 +02:00
|
|
|
// multiple typeof operator
|
2014-07-13 01:04:16 +02:00
|
|
|
var ResultIsString8 = typeof typeof BOOLEAN;
|
2014-08-16 00:49:09 +02:00
|
|
|
// miss assignment operators
|
2014-07-13 01:04:16 +02:00
|
|
|
typeof true;
|
|
|
|
typeof BOOLEAN;
|
|
|
|
typeof foo();
|
|
|
|
typeof true, false;
|
|
|
|
typeof objA.a;
|
|
|
|
typeof M.n;
|
2014-08-12 00:54:12 +02:00
|
|
|
// use typeof in type query
|
2014-07-13 01:04:16 +02:00
|
|
|
var z;
|
|
|
|
var x;
|
|
|
|
var r;
|
|
|
|
z: typeof BOOLEAN;
|
|
|
|
r: typeof foo;
|
|
|
|
var y = { a: true, b: false };
|
|
|
|
z: typeof y.a;
|
|
|
|
z: typeof objA.a;
|
|
|
|
z: typeof A.foo;
|
|
|
|
z: typeof M.n;
|