214 lines
4.3 KiB
Text
214 lines
4.3 KiB
Text
|
=== 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[]
|
||
|
|
||
|
function foo(): string { return "abc"; }
|
||
|
>foo : () => string
|
||
|
|
||
|
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
|
||
|
>typeof STRING : string
|
||
|
>STRING : string
|
||
|
|
||
|
var ResultIsString2 = typeof STRING1;
|
||
|
>ResultIsString2 : string
|
||
|
>typeof STRING1 : string
|
||
|
>STRING1 : string[]
|
||
|
|
||
|
// string type literal
|
||
|
var ResultIsString3 = typeof "";
|
||
|
>ResultIsString3 : string
|
||
|
>typeof "" : string
|
||
|
|
||
|
var ResultIsString4 = typeof { x: "", y: "" };
|
||
|
>ResultIsString4 : string
|
||
|
>typeof { x: "", y: "" } : string
|
||
|
>{ x: "", y: "" } : { x: string; y: string; }
|
||
|
>x : string
|
||
|
>y : string
|
||
|
|
||
|
var ResultIsString5 = typeof { x: "", y: (s: string) => { return s; } };
|
||
|
>ResultIsString5 : string
|
||
|
>typeof { x: "", y: (s: string) => { return s; } } : string
|
||
|
>{ 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
|
||
|
>typeof objA.a : string
|
||
|
>objA.a : string
|
||
|
>objA : A
|
||
|
>a : string
|
||
|
|
||
|
var ResultIsString7 = typeof M.n;
|
||
|
>ResultIsString7 : string
|
||
|
>typeof M.n : string
|
||
|
>M.n : string
|
||
|
>M : typeof M
|
||
|
>n : string
|
||
|
|
||
|
var ResultIsString8 = typeof STRING1[0];
|
||
|
>ResultIsString8 : string
|
||
|
>typeof STRING1[0] : string
|
||
|
>STRING1[0] : string
|
||
|
>STRING1 : string[]
|
||
|
|
||
|
var ResultIsString9 = typeof foo();
|
||
|
>ResultIsString9 : string
|
||
|
>typeof foo() : string
|
||
|
>foo() : string
|
||
|
>foo : () => string
|
||
|
|
||
|
var ResultIsString10 = typeof A.foo();
|
||
|
>ResultIsString10 : string
|
||
|
>typeof A.foo() : string
|
||
|
>A.foo() : string
|
||
|
>A.foo : () => string
|
||
|
>A : typeof A
|
||
|
>foo : () => string
|
||
|
|
||
|
var ResultIsString11 = typeof (STRING + STRING);
|
||
|
>ResultIsString11 : string
|
||
|
>typeof (STRING + STRING) : string
|
||
|
>(STRING + STRING) : string
|
||
|
>STRING + STRING : string
|
||
|
>STRING : string
|
||
|
>STRING : string
|
||
|
|
||
|
var ResultIsString12 = typeof STRING.charAt(0);
|
||
|
>ResultIsString12 : string
|
||
|
>typeof STRING.charAt(0) : string
|
||
|
>STRING.charAt(0) : string
|
||
|
>STRING.charAt : (pos: number) => string
|
||
|
>STRING : string
|
||
|
>charAt : (pos: number) => string
|
||
|
|
||
|
// multiple typeof operators
|
||
|
var ResultIsString13 = typeof typeof STRING;
|
||
|
>ResultIsString13 : string
|
||
|
>typeof typeof STRING : string
|
||
|
>typeof STRING : string
|
||
|
>STRING : string
|
||
|
|
||
|
var ResultIsString14 = typeof typeof typeof (STRING + STRING);
|
||
|
>ResultIsString14 : string
|
||
|
>typeof typeof typeof (STRING + STRING) : string
|
||
|
>typeof typeof (STRING + STRING) : string
|
||
|
>typeof (STRING + STRING) : string
|
||
|
>(STRING + STRING) : string
|
||
|
>STRING + STRING : string
|
||
|
>STRING : string
|
||
|
>STRING : string
|
||
|
|
||
|
// miss assignment operators
|
||
|
typeof "";
|
||
|
>typeof "" : string
|
||
|
|
||
|
typeof STRING;
|
||
|
>typeof STRING : string
|
||
|
>STRING : string
|
||
|
|
||
|
typeof STRING1;
|
||
|
>typeof STRING1 : string
|
||
|
>STRING1 : string[]
|
||
|
|
||
|
typeof foo();
|
||
|
>typeof foo() : string
|
||
|
>foo() : string
|
||
|
>foo : () => string
|
||
|
|
||
|
typeof objA.a, M.n;
|
||
|
>typeof objA.a, M.n : string
|
||
|
>typeof objA.a : string
|
||
|
>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;
|
||
|
>typeof STRING : string
|
||
|
>STRING : string
|
||
|
|
||
|
x: typeof STRING1;
|
||
|
>typeof STRING1 : string
|
||
|
>STRING1 : string[]
|
||
|
|
||
|
r: typeof foo;
|
||
|
>typeof foo : string
|
||
|
>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;
|
||
|
>typeof y.a : string
|
||
|
>y.a : string
|
||
|
>y : { a: string; b: string; }
|
||
|
>a : string
|
||
|
|
||
|
z: typeof objA.a;
|
||
|
>typeof objA.a : string
|
||
|
>objA.a : string
|
||
|
>objA : A
|
||
|
>a : string
|
||
|
|
||
|
z: typeof A.foo;
|
||
|
>typeof A.foo : string
|
||
|
>A.foo : () => string
|
||
|
>A : typeof A
|
||
|
>foo : () => string
|
||
|
|
||
|
z: typeof M.n;
|
||
|
>typeof M.n : string
|
||
|
>M.n : string
|
||
|
>M : typeof M
|
||
|
>n : string
|
||
|
|