mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Added more tests.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// @declaration: true
|
||||
|
||||
interface Base {
|
||||
x: string;
|
||||
y: number;
|
||||
}
|
||||
|
||||
interface HelloOrWorld extends Base {
|
||||
p1: boolean;
|
||||
}
|
||||
|
||||
interface JustHello extends Base {
|
||||
p2: boolean;
|
||||
}
|
||||
|
||||
interface JustWorld extends Base {
|
||||
p3: boolean;
|
||||
}
|
||||
|
||||
let hello: "hello";
|
||||
let world: "world";
|
||||
let helloOrWorld: "hello" | "world";
|
||||
|
||||
function f(p: "hello"): JustHello;
|
||||
function f(p: "hello" | "world"): HelloOrWorld;
|
||||
function f(p: "world"): JustWorld;
|
||||
function f(p: string): Base;
|
||||
function f(...args: any[]): any {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let fResult1 = f(hello);
|
||||
let fResult2 = f(world);
|
||||
let fResult3 = f(helloOrWorld);
|
||||
|
||||
function g(p: string): Base;
|
||||
function g(p: "hello"): JustHello;
|
||||
function g(p: "hello" | "world"): HelloOrWorld;
|
||||
function g(p: "world"): JustWorld;
|
||||
function g(...args: any[]): any {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let gResult1 = g(hello);
|
||||
let gResult2 = g(world);
|
||||
let gResult3 = g(helloOrWorld);
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// @declaration: true
|
||||
|
||||
let abc: "ABC" = "ABC";
|
||||
let xyz: "XYZ" = "XYZ";
|
||||
let abcOrXyz: "ABC" | "XYZ" = abc || xyz;
|
||||
let abcOrXyzOrNumber: "ABC" | "XYZ" | number = abcOrXyz || 100;
|
||||
|
||||
let a = "" + abc;
|
||||
let b = abc + "";
|
||||
let c = 10 + abc;
|
||||
let d = abc + 10;
|
||||
let e = xyz + abc;
|
||||
let f = abc + xyz;
|
||||
let g = true + abc;
|
||||
let h = abc + true;
|
||||
let i = abc + abcOrXyz + xyz;
|
||||
let j = abcOrXyz + abcOrXyz;
|
||||
let k = +abcOrXyz;
|
||||
let l = -abcOrXyz;
|
||||
let m = abcOrXyzOrNumber + "";
|
||||
let n = "" + abcOrXyzOrNumber;
|
||||
let o = abcOrXyzOrNumber + abcOrXyz;
|
||||
let p = abcOrXyz + abcOrXyzOrNumber;
|
||||
let q = !abcOrXyzOrNumber;
|
||||
let r = ~abcOrXyzOrNumber;
|
||||
let s = abcOrXyzOrNumber < abcOrXyzOrNumber;
|
||||
let t = abcOrXyzOrNumber >= abcOrXyz;
|
||||
let u = abc === abcOrXyz;
|
||||
let v = abcOrXyz === abcOrXyzOrNumber;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// @declaration: true
|
||||
|
||||
let abc: "ABC" = "ABC";
|
||||
let xyz: "XYZ" = "XYZ";
|
||||
let abcOrXyz: "ABC" | "XYZ" = abc || xyz;
|
||||
let abcOrXyzOrNumber: "ABC" | "XYZ" | number = abcOrXyz || 100;
|
||||
|
||||
let a = abcOrXyzOrNumber + 100;
|
||||
let b = 100 + abcOrXyzOrNumber;
|
||||
let c = abcOrXyzOrNumber + abcOrXyzOrNumber;
|
||||
let d = abcOrXyzOrNumber + true;
|
||||
let e = false + abcOrXyzOrNumber;
|
||||
let f = abcOrXyzOrNumber++;
|
||||
let g = --abcOrXyzOrNumber;
|
||||
let h = abcOrXyzOrNumber ^ 10;
|
||||
let i = abcOrXyzOrNumber | 10;
|
||||
let j = abc < xyz;
|
||||
let k = abc === xyz;
|
||||
let l = abc != xyz;
|
||||
Reference in New Issue
Block a user