176 lines
3.2 KiB
Text
176 lines
3.2 KiB
Text
=== tests/cases/conformance/expressions/unaryOperators/typeofOperator/typeofOperatorWithBooleanType.ts ===
|
|
// typeof operator on boolean type
|
|
var BOOLEAN: boolean;
|
|
>BOOLEAN : boolean
|
|
|
|
function foo(): boolean { return true; }
|
|
>foo : () => boolean
|
|
>true : boolean
|
|
|
|
class A {
|
|
>A : A
|
|
|
|
public a: boolean;
|
|
>a : boolean
|
|
|
|
static foo() { return false; }
|
|
>foo : () => boolean
|
|
>false : boolean
|
|
}
|
|
module M {
|
|
>M : typeof M
|
|
|
|
export var n: boolean;
|
|
>n : boolean
|
|
}
|
|
|
|
var objA = new A();
|
|
>objA : A
|
|
>new A() : A
|
|
>A : typeof A
|
|
|
|
// boolean type var
|
|
var ResultIsString1 = typeof BOOLEAN;
|
|
>ResultIsString1 : string
|
|
>typeof BOOLEAN : string
|
|
>BOOLEAN : boolean
|
|
|
|
// boolean type literal
|
|
var ResultIsString2 = typeof true;
|
|
>ResultIsString2 : string
|
|
>typeof true : string
|
|
>true : boolean
|
|
|
|
var ResultIsString3 = typeof { x: true, y: false };
|
|
>ResultIsString3 : string
|
|
>typeof { x: true, y: false } : string
|
|
>{ x: true, y: false } : { x: boolean; y: boolean; }
|
|
>x : boolean
|
|
>true : boolean
|
|
>y : boolean
|
|
>false : boolean
|
|
|
|
// boolean type expressions
|
|
var ResultIsString4 = typeof objA.a;
|
|
>ResultIsString4 : string
|
|
>typeof objA.a : string
|
|
>objA.a : boolean
|
|
>objA : A
|
|
>a : boolean
|
|
|
|
var ResultIsString5 = typeof M.n;
|
|
>ResultIsString5 : string
|
|
>typeof M.n : string
|
|
>M.n : boolean
|
|
>M : typeof M
|
|
>n : boolean
|
|
|
|
var ResultIsString6 = typeof foo();
|
|
>ResultIsString6 : string
|
|
>typeof foo() : string
|
|
>foo() : boolean
|
|
>foo : () => boolean
|
|
|
|
var ResultIsString7 = typeof A.foo();
|
|
>ResultIsString7 : string
|
|
>typeof A.foo() : string
|
|
>A.foo() : boolean
|
|
>A.foo : () => boolean
|
|
>A : typeof A
|
|
>foo : () => boolean
|
|
|
|
// multiple typeof operator
|
|
var ResultIsString8 = typeof typeof BOOLEAN;
|
|
>ResultIsString8 : string
|
|
>typeof typeof BOOLEAN : string
|
|
>typeof BOOLEAN : string
|
|
>BOOLEAN : boolean
|
|
|
|
// miss assignment operators
|
|
typeof true;
|
|
>typeof true : string
|
|
>true : boolean
|
|
|
|
typeof BOOLEAN;
|
|
>typeof BOOLEAN : string
|
|
>BOOLEAN : boolean
|
|
|
|
typeof foo();
|
|
>typeof foo() : string
|
|
>foo() : boolean
|
|
>foo : () => boolean
|
|
|
|
typeof true, false;
|
|
>typeof true, false : boolean
|
|
>typeof true : string
|
|
>true : boolean
|
|
>false : boolean
|
|
|
|
typeof objA.a;
|
|
>typeof objA.a : string
|
|
>objA.a : boolean
|
|
>objA : A
|
|
>a : boolean
|
|
|
|
typeof M.n;
|
|
>typeof M.n : string
|
|
>M.n : boolean
|
|
>M : typeof M
|
|
>n : boolean
|
|
|
|
// use typeof in type query
|
|
var z: boolean;
|
|
>z : boolean
|
|
|
|
var x: boolean[];
|
|
>x : boolean[]
|
|
|
|
var r: () => boolean;
|
|
>r : () => boolean
|
|
|
|
z: typeof BOOLEAN;
|
|
>z : any
|
|
>typeof BOOLEAN : string
|
|
>BOOLEAN : boolean
|
|
|
|
r: typeof foo;
|
|
>r : any
|
|
>typeof foo : string
|
|
>foo : () => boolean
|
|
|
|
var y = { a: true, b: false};
|
|
>y : { a: boolean; b: boolean; }
|
|
>{ a: true, b: false} : { a: boolean; b: boolean; }
|
|
>a : boolean
|
|
>true : boolean
|
|
>b : boolean
|
|
>false : boolean
|
|
|
|
z: typeof y.a;
|
|
>z : any
|
|
>typeof y.a : string
|
|
>y.a : boolean
|
|
>y : { a: boolean; b: boolean; }
|
|
>a : boolean
|
|
|
|
z: typeof objA.a;
|
|
>z : any
|
|
>typeof objA.a : string
|
|
>objA.a : boolean
|
|
>objA : A
|
|
>a : boolean
|
|
|
|
z: typeof A.foo;
|
|
>z : any
|
|
>typeof A.foo : string
|
|
>A.foo : () => boolean
|
|
>A : typeof A
|
|
>foo : () => boolean
|
|
|
|
z: typeof M.n;
|
|
>z : any
|
|
>typeof M.n : string
|
|
>M.n : boolean
|
|
>M : typeof M
|
|
>n : boolean
|
|
|