added basic set of tests for type aliases
This commit is contained in:
parent
d86d520c33
commit
6b1a96ca29
|
@ -1,30 +1,126 @@
|
|||
//// [typeAliases.ts]
|
||||
// Writing a reference to a type alias has exactly the same effect as writing the aliased type itself.
|
||||
|
||||
type T1 = number;
|
||||
var x1: number;
|
||||
var x1: T1;
|
||||
|
||||
type T2 = string;
|
||||
var x2: string;
|
||||
var x2: T2;
|
||||
|
||||
type T3 = boolean;
|
||||
var x3: boolean;
|
||||
var x3: T3;
|
||||
|
||||
type T4 = void;
|
||||
var x4: void;
|
||||
var x4: T4;
|
||||
|
||||
type T5 = any;
|
||||
var x5: any;
|
||||
var x5: T5;
|
||||
|
||||
interface I6 { x : string }
|
||||
type T6 = I6;
|
||||
var x6: I6;
|
||||
var x6: T6;
|
||||
|
||||
class C7 { x: boolean }
|
||||
type T7 = C7;
|
||||
var x7: C7;
|
||||
var x7: T7;
|
||||
|
||||
type T8 = string | boolean;
|
||||
var x8: string | boolean;
|
||||
var x8: T8;
|
||||
|
||||
type T9 = () => string;
|
||||
var x9: () => string;
|
||||
var x9: T9;
|
||||
|
||||
type T10 = { x: number };
|
||||
var x10: { x: number };
|
||||
var x10: T10;
|
||||
|
||||
type T11 = { new(): boolean };
|
||||
var x11: { new(): boolean };
|
||||
var x11: T11;
|
||||
|
||||
interface I13 { x: string };
|
||||
type T13 = I13;
|
||||
var x13_1: I13;
|
||||
var x13_2: T13
|
||||
|
||||
declare function foo13<T1 extends I13, T2 extends T13>(t1: T1, t2: T13): void;
|
||||
foo13(x13_1, x13_2);
|
||||
foo13(x13_2, x13_1);
|
||||
|
||||
type T14 = string;
|
||||
var x14: T14;
|
||||
|
||||
declare function foo14_1(x: T14): void;
|
||||
|
||||
declare function foo14_2(x: "click"): void;
|
||||
declare function foo14_2(x: T14): void;
|
||||
|
||||
type Meters = number
|
||||
|
||||
enum E { x = 10 }
|
||||
|
||||
declare function f(a: string): boolean;
|
||||
declare function f(a: Meters): string;
|
||||
f(E.x).toLowerCase();
|
||||
declare function f15(a: string): boolean;
|
||||
declare function f15(a: Meters): string;
|
||||
f15(E.x).toLowerCase();
|
||||
|
||||
type StringAndBoolean = [string, boolean]
|
||||
declare function f1(s: StringAndBoolean): string;
|
||||
declare function f16(s: StringAndBoolean): string;
|
||||
var x: [string, boolean];
|
||||
f1(x);
|
||||
f16(x);
|
||||
|
||||
var y: StringAndBoolean = ["1", false];
|
||||
y[0].toLowerCase();
|
||||
|
||||
//// [typeAliases.js]
|
||||
// Writing a reference to a type alias has exactly the same effect as writing the aliased type itself.
|
||||
var x1;
|
||||
var x1;
|
||||
var x2;
|
||||
var x2;
|
||||
var x3;
|
||||
var x3;
|
||||
var x4;
|
||||
var x4;
|
||||
var x5;
|
||||
var x5;
|
||||
var x6;
|
||||
var x6;
|
||||
var C7 = (function () {
|
||||
function C7() {
|
||||
}
|
||||
return C7;
|
||||
})();
|
||||
var x7;
|
||||
var x7;
|
||||
var x8;
|
||||
var x8;
|
||||
var x9;
|
||||
var x9;
|
||||
var x10;
|
||||
var x10;
|
||||
var x11;
|
||||
var x11;
|
||||
;
|
||||
var x13_1;
|
||||
var x13_2;
|
||||
foo13(x13_1, x13_2);
|
||||
foo13(x13_2, x13_1);
|
||||
var x14;
|
||||
var E;
|
||||
(function (E) {
|
||||
E[E["x"] = 10] = "x";
|
||||
})(E || (E = {}));
|
||||
f(10 /* x */).toLowerCase();
|
||||
f15(10 /* x */).toLowerCase();
|
||||
var x;
|
||||
f1(x);
|
||||
f16(x);
|
||||
var y = ["1", false];
|
||||
y[0].toLowerCase();
|
||||
|
|
|
@ -1,6 +1,190 @@
|
|||
=== tests/cases/conformance/types/typeAliases/typeAliases.ts ===
|
||||
// Writing a reference to a type alias has exactly the same effect as writing the aliased type itself.
|
||||
|
||||
type T1 = number;
|
||||
>T1 : number
|
||||
|
||||
var x1: number;
|
||||
>x1 : number
|
||||
|
||||
var x1: T1;
|
||||
>x1 : number
|
||||
>T1 : number
|
||||
|
||||
type T2 = string;
|
||||
>T2 : string
|
||||
|
||||
var x2: string;
|
||||
>x2 : string
|
||||
|
||||
var x2: T2;
|
||||
>x2 : string
|
||||
>T2 : string
|
||||
|
||||
type T3 = boolean;
|
||||
>T3 : boolean
|
||||
|
||||
var x3: boolean;
|
||||
>x3 : boolean
|
||||
|
||||
var x3: T3;
|
||||
>x3 : boolean
|
||||
>T3 : boolean
|
||||
|
||||
type T4 = void;
|
||||
>T4 : void
|
||||
|
||||
var x4: void;
|
||||
>x4 : void
|
||||
|
||||
var x4: T4;
|
||||
>x4 : void
|
||||
>T4 : void
|
||||
|
||||
type T5 = any;
|
||||
>T5 : any
|
||||
|
||||
var x5: any;
|
||||
>x5 : any
|
||||
|
||||
var x5: T5;
|
||||
>x5 : any
|
||||
>T5 : any
|
||||
|
||||
interface I6 { x : string }
|
||||
>I6 : I6
|
||||
>x : string
|
||||
|
||||
type T6 = I6;
|
||||
>T6 : I6
|
||||
>I6 : I6
|
||||
|
||||
var x6: I6;
|
||||
>x6 : I6
|
||||
>I6 : I6
|
||||
|
||||
var x6: T6;
|
||||
>x6 : I6
|
||||
>T6 : I6
|
||||
|
||||
class C7 { x: boolean }
|
||||
>C7 : C7
|
||||
>x : boolean
|
||||
|
||||
type T7 = C7;
|
||||
>T7 : C7
|
||||
>C7 : C7
|
||||
|
||||
var x7: C7;
|
||||
>x7 : C7
|
||||
>C7 : C7
|
||||
|
||||
var x7: T7;
|
||||
>x7 : C7
|
||||
>T7 : C7
|
||||
|
||||
type T8 = string | boolean;
|
||||
>T8 : string | boolean
|
||||
|
||||
var x8: string | boolean;
|
||||
>x8 : string | boolean
|
||||
|
||||
var x8: T8;
|
||||
>x8 : string | boolean
|
||||
>T8 : string | boolean
|
||||
|
||||
type T9 = () => string;
|
||||
>T9 : () => string
|
||||
|
||||
var x9: () => string;
|
||||
>x9 : () => string
|
||||
|
||||
var x9: T9;
|
||||
>x9 : () => string
|
||||
>T9 : () => string
|
||||
|
||||
type T10 = { x: number };
|
||||
>T10 : { x: number; }
|
||||
>x : number
|
||||
|
||||
var x10: { x: number };
|
||||
>x10 : { x: number; }
|
||||
>x : number
|
||||
|
||||
var x10: T10;
|
||||
>x10 : { x: number; }
|
||||
>T10 : { x: number; }
|
||||
|
||||
type T11 = { new(): boolean };
|
||||
>T11 : new () => boolean
|
||||
|
||||
var x11: { new(): boolean };
|
||||
>x11 : new () => boolean
|
||||
|
||||
var x11: T11;
|
||||
>x11 : new () => boolean
|
||||
>T11 : new () => boolean
|
||||
|
||||
interface I13 { x: string };
|
||||
>I13 : I13
|
||||
>x : string
|
||||
|
||||
type T13 = I13;
|
||||
>T13 : I13
|
||||
>I13 : I13
|
||||
|
||||
var x13_1: I13;
|
||||
>x13_1 : I13
|
||||
>I13 : I13
|
||||
|
||||
var x13_2: T13
|
||||
>x13_2 : I13
|
||||
>T13 : I13
|
||||
|
||||
declare function foo13<T1 extends I13, T2 extends T13>(t1: T1, t2: T13): void;
|
||||
>foo13 : <T1 extends I13, T2 extends I13>(t1: T1, t2: I13) => void
|
||||
>T1 : T1
|
||||
>I13 : I13
|
||||
>T2 : T2
|
||||
>T13 : I13
|
||||
>t1 : T1
|
||||
>T1 : T1
|
||||
>t2 : I13
|
||||
>T13 : I13
|
||||
|
||||
foo13(x13_1, x13_2);
|
||||
>foo13(x13_1, x13_2) : void
|
||||
>foo13 : <T1 extends I13, T2 extends I13>(t1: T1, t2: I13) => void
|
||||
>x13_1 : I13
|
||||
>x13_2 : I13
|
||||
|
||||
foo13(x13_2, x13_1);
|
||||
>foo13(x13_2, x13_1) : void
|
||||
>foo13 : <T1 extends I13, T2 extends I13>(t1: T1, t2: I13) => void
|
||||
>x13_2 : I13
|
||||
>x13_1 : I13
|
||||
|
||||
type T14 = string;
|
||||
>T14 : string
|
||||
|
||||
var x14: T14;
|
||||
>x14 : string
|
||||
>T14 : string
|
||||
|
||||
declare function foo14_1(x: T14): void;
|
||||
>foo14_1 : (x: string) => void
|
||||
>x : string
|
||||
>T14 : string
|
||||
|
||||
declare function foo14_2(x: "click"): void;
|
||||
>foo14_2 : { (x: "click"): void; (x: string): void; }
|
||||
>x : "click"
|
||||
|
||||
declare function foo14_2(x: T14): void;
|
||||
>foo14_2 : { (x: "click"): void; (x: string): void; }
|
||||
>x : string
|
||||
>T14 : string
|
||||
|
||||
type Meters = number
|
||||
>Meters : number
|
||||
|
||||
|
@ -8,20 +192,20 @@ enum E { x = 10 }
|
|||
>E : E
|
||||
>x : E
|
||||
|
||||
declare function f(a: string): boolean;
|
||||
>f : { (a: string): boolean; (a: number): string; }
|
||||
declare function f15(a: string): boolean;
|
||||
>f15 : { (a: string): boolean; (a: number): string; }
|
||||
>a : string
|
||||
|
||||
declare function f(a: Meters): string;
|
||||
>f : { (a: string): boolean; (a: number): string; }
|
||||
declare function f15(a: Meters): string;
|
||||
>f15 : { (a: string): boolean; (a: number): string; }
|
||||
>a : number
|
||||
>Meters : number
|
||||
|
||||
f(E.x).toLowerCase();
|
||||
>f(E.x).toLowerCase() : string
|
||||
>f(E.x).toLowerCase : () => string
|
||||
>f(E.x) : string
|
||||
>f : { (a: string): boolean; (a: number): string; }
|
||||
f15(E.x).toLowerCase();
|
||||
>f15(E.x).toLowerCase() : string
|
||||
>f15(E.x).toLowerCase : () => string
|
||||
>f15(E.x) : string
|
||||
>f15 : { (a: string): boolean; (a: number): string; }
|
||||
>E.x : E
|
||||
>E : typeof E
|
||||
>x : E
|
||||
|
@ -30,17 +214,17 @@ f(E.x).toLowerCase();
|
|||
type StringAndBoolean = [string, boolean]
|
||||
>StringAndBoolean : [string, boolean]
|
||||
|
||||
declare function f1(s: StringAndBoolean): string;
|
||||
>f1 : (s: [string, boolean]) => string
|
||||
declare function f16(s: StringAndBoolean): string;
|
||||
>f16 : (s: [string, boolean]) => string
|
||||
>s : [string, boolean]
|
||||
>StringAndBoolean : [string, boolean]
|
||||
|
||||
var x: [string, boolean];
|
||||
>x : [string, boolean]
|
||||
|
||||
f1(x);
|
||||
>f1(x) : string
|
||||
>f1 : (s: [string, boolean]) => string
|
||||
f16(x);
|
||||
>f16(x) : string
|
||||
>f16 : (s: [string, boolean]) => string
|
||||
>x : [string, boolean]
|
||||
|
||||
var y: StringAndBoolean = ["1", false];
|
||||
|
|
|
@ -1,17 +1,80 @@
|
|||
// Writing a reference to a type alias has exactly the same effect as writing the aliased type itself.
|
||||
|
||||
type T1 = number;
|
||||
var x1: number;
|
||||
var x1: T1;
|
||||
|
||||
type T2 = string;
|
||||
var x2: string;
|
||||
var x2: T2;
|
||||
|
||||
type T3 = boolean;
|
||||
var x3: boolean;
|
||||
var x3: T3;
|
||||
|
||||
type T4 = void;
|
||||
var x4: void;
|
||||
var x4: T4;
|
||||
|
||||
type T5 = any;
|
||||
var x5: any;
|
||||
var x5: T5;
|
||||
|
||||
interface I6 { x : string }
|
||||
type T6 = I6;
|
||||
var x6: I6;
|
||||
var x6: T6;
|
||||
|
||||
class C7 { x: boolean }
|
||||
type T7 = C7;
|
||||
var x7: C7;
|
||||
var x7: T7;
|
||||
|
||||
type T8 = string | boolean;
|
||||
var x8: string | boolean;
|
||||
var x8: T8;
|
||||
|
||||
type T9 = () => string;
|
||||
var x9: () => string;
|
||||
var x9: T9;
|
||||
|
||||
type T10 = { x: number };
|
||||
var x10: { x: number };
|
||||
var x10: T10;
|
||||
|
||||
type T11 = { new(): boolean };
|
||||
var x11: { new(): boolean };
|
||||
var x11: T11;
|
||||
|
||||
interface I13 { x: string };
|
||||
type T13 = I13;
|
||||
var x13_1: I13;
|
||||
var x13_2: T13
|
||||
|
||||
declare function foo13<T1 extends I13, T2 extends T13>(t1: T1, t2: T13): void;
|
||||
foo13(x13_1, x13_2);
|
||||
foo13(x13_2, x13_1);
|
||||
|
||||
type T14 = string;
|
||||
var x14: T14;
|
||||
|
||||
declare function foo14_1(x: T14): void;
|
||||
|
||||
declare function foo14_2(x: "click"): void;
|
||||
declare function foo14_2(x: T14): void;
|
||||
|
||||
type Meters = number
|
||||
|
||||
enum E { x = 10 }
|
||||
|
||||
declare function f(a: string): boolean;
|
||||
declare function f(a: Meters): string;
|
||||
f(E.x).toLowerCase();
|
||||
declare function f15(a: string): boolean;
|
||||
declare function f15(a: Meters): string;
|
||||
f15(E.x).toLowerCase();
|
||||
|
||||
type StringAndBoolean = [string, boolean]
|
||||
declare function f1(s: StringAndBoolean): string;
|
||||
declare function f16(s: StringAndBoolean): string;
|
||||
var x: [string, boolean];
|
||||
f1(x);
|
||||
f16(x);
|
||||
|
||||
var y: StringAndBoolean = ["1", false];
|
||||
y[0].toLowerCase();
|
Loading…
Reference in a new issue