2014-07-13 01:04:16 +02:00
|
|
|
//// [typeofOperatorWithNumberType.ts]
|
|
|
|
// typeof operator on number type
|
|
|
|
var NUMBER: number;
|
|
|
|
var NUMBER1: number[] = [1, 2];
|
|
|
|
|
|
|
|
function foo(): number { return 1; }
|
|
|
|
|
|
|
|
class A {
|
|
|
|
public a: number;
|
|
|
|
static foo() { return 1; }
|
|
|
|
}
|
|
|
|
module M {
|
|
|
|
export var n: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
var objA = new A();
|
|
|
|
|
|
|
|
// number type var
|
|
|
|
var ResultIsString1 = typeof NUMBER;
|
|
|
|
var ResultIsString2 = typeof NUMBER1;
|
|
|
|
|
|
|
|
// number type literal
|
|
|
|
var ResultIsString3 = typeof 1;
|
|
|
|
var ResultIsString4 = typeof { x: 1, y: 2};
|
|
|
|
var ResultIsString5 = typeof { x: 1, y: (n: number) => { return n; } };
|
|
|
|
|
|
|
|
// number type expressions
|
|
|
|
var ResultIsString6 = typeof objA.a;
|
|
|
|
var ResultIsString7 = typeof M.n;
|
|
|
|
var ResultIsString8 = typeof NUMBER1[0];
|
|
|
|
var ResultIsString9 = typeof foo();
|
|
|
|
var ResultIsString10 = typeof A.foo();
|
|
|
|
var ResultIsString11 = typeof (NUMBER + NUMBER);
|
|
|
|
|
|
|
|
// multiple typeof operators
|
|
|
|
var ResultIsString12 = typeof typeof NUMBER;
|
|
|
|
var ResultIsString13 = typeof typeof typeof (NUMBER + NUMBER);
|
|
|
|
|
|
|
|
// miss assignment operators
|
|
|
|
typeof 1;
|
|
|
|
typeof NUMBER;
|
|
|
|
typeof NUMBER1;
|
|
|
|
typeof foo();
|
|
|
|
typeof objA.a;
|
|
|
|
typeof M.n;
|
|
|
|
typeof objA.a, M.n;
|
|
|
|
|
|
|
|
// use typeof in type query
|
|
|
|
var z: number;
|
|
|
|
var x: number[];
|
|
|
|
z: typeof NUMBER;
|
|
|
|
x: typeof NUMBER1;
|
|
|
|
r: typeof foo;
|
|
|
|
var y = { a: 1, b: 2 };
|
|
|
|
z: typeof y.a;
|
|
|
|
z: typeof objA.a;
|
|
|
|
z: typeof A.foo;
|
|
|
|
z: typeof M.n;
|
|
|
|
|
|
|
|
//// [typeofOperatorWithNumberType.js]
|
2014-08-12 00:54:12 +02:00
|
|
|
// typeof operator on number type
|
2014-07-13 01:04:16 +02:00
|
|
|
var NUMBER;
|
|
|
|
var NUMBER1 = [1, 2];
|
|
|
|
function foo() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
var A = (function () {
|
|
|
|
function A() {
|
|
|
|
}
|
|
|
|
A.foo = function () {
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
return A;
|
|
|
|
})();
|
|
|
|
var M;
|
|
|
|
(function (M) {
|
|
|
|
M.n;
|
|
|
|
})(M || (M = {}));
|
|
|
|
var objA = new A();
|
2014-08-12 00:54:12 +02:00
|
|
|
// number type var
|
2014-07-13 01:04:16 +02:00
|
|
|
var ResultIsString1 = typeof NUMBER;
|
|
|
|
var ResultIsString2 = typeof NUMBER1;
|
2014-08-12 00:54:12 +02:00
|
|
|
// number type literal
|
2014-07-13 01:04:16 +02:00
|
|
|
var ResultIsString3 = typeof 1;
|
|
|
|
var ResultIsString4 = typeof { x: 1, y: 2 };
|
|
|
|
var ResultIsString5 = typeof { x: 1, y: function (n) {
|
|
|
|
return n;
|
|
|
|
} };
|
2014-08-12 00:54:12 +02:00
|
|
|
// number type expressions
|
2014-07-13 01:04:16 +02:00
|
|
|
var ResultIsString6 = typeof objA.a;
|
|
|
|
var ResultIsString7 = typeof M.n;
|
|
|
|
var ResultIsString8 = typeof NUMBER1[0];
|
|
|
|
var ResultIsString9 = typeof foo();
|
|
|
|
var ResultIsString10 = typeof A.foo();
|
|
|
|
var ResultIsString11 = typeof (NUMBER + NUMBER);
|
2014-08-12 00:54:12 +02:00
|
|
|
// multiple typeof operators
|
2014-07-13 01:04:16 +02:00
|
|
|
var ResultIsString12 = typeof typeof NUMBER;
|
|
|
|
var ResultIsString13 = typeof typeof typeof (NUMBER + NUMBER);
|
2014-08-16 00:49:09 +02:00
|
|
|
// miss assignment operators
|
2014-07-13 01:04:16 +02:00
|
|
|
typeof 1;
|
|
|
|
typeof NUMBER;
|
|
|
|
typeof NUMBER1;
|
|
|
|
typeof foo();
|
|
|
|
typeof objA.a;
|
|
|
|
typeof M.n;
|
|
|
|
typeof objA.a, 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;
|
|
|
|
z: typeof NUMBER;
|
|
|
|
x: typeof NUMBER1;
|
|
|
|
r: typeof foo;
|
|
|
|
var y = { a: 1, b: 2 };
|
|
|
|
z: typeof y.a;
|
|
|
|
z: typeof objA.a;
|
|
|
|
z: typeof A.foo;
|
|
|
|
z: typeof M.n;
|