Add tests

This commit is contained in:
Anders Hejlsberg 2016-09-11 11:23:21 -07:00
parent 2344a80e6f
commit ef81594117
4 changed files with 1944 additions and 0 deletions

View file

@ -0,0 +1,348 @@
//// [literalTypes2.ts]
enum E {
A, B, C
}
let cond: boolean;
function f1(p1 = 1, p2 = "abc", p3 = true, p4 = E.A) {
var v1 = 1;
var v2 = -123;
var v3 = 3 + 4;
var v4 = "abc";
var v5 = "";
var v6 = "abc" + "def";
var v7 = true;
var v8 = E.A;
let x1 = 1;
let x2 = -123;
let x3 = 3 + 4;
let x4 = "abc";
let x5 = "";
let x6 = "abc" + "def";
let x7 = true;
var x8 = E.A;
const c1 = 1;
const c2 = -123;
const c3 = 3 + 4;
const c4 = "abc";
const c5 = "";
const c6 = "abc" + "def";
const c7 = true;
const c8 = E.A;
}
function f2(p1: 1 = 1, p2: "abc" = "abc", p3: true = true, p4: E.A = E.A) {
var v1: 1 = 1;
var v2: -123 = -123;
var v3: "abc" = "abc";
var v4: true = true;
var v5: E.A = E.A;
let x1: 1 = 1;
let x2: -123 = -123;
let x3: "abc" = "abc";
let x4: true = true;
let x5: E.A = E.A;
}
function f3() {
const c1 = cond ? 1 : 2;
const c2 = cond ? 1 : "two";
const c3 = cond ? E.A : cond ? true : 123;
const c4 = cond ? "abc" : null;
const c5 = cond ? 456 : undefined;
const c6: { kind: 123 } = { kind: 123 };
const c7: [1 | 2, "foo" | "bar"] = [1, "bar"];
const c8 = cond ? c6 : cond ? c7 : "hello";
let x1 = c1;
let x2 = c2;
let x3 = c3;
let x4 = c4;
let x5 = c5;
let x6 = c6;
let x7 = c7;
let x8 = c8;
}
class C1 {
x1 = 1;
x2 = -123;
x3 = 3 + 4;
x4 = "abc";
x5 = "";
x6 = "abc" + "def";
x7 = true;
x8 = E.A;
readonly c1 = 1;
readonly c2 = -123;
readonly c3 = 3 + 4;
readonly c4 = "abc";
readonly c5 = "";
readonly c6 = "abc" + "def";
readonly c7 = true;
readonly c8 = E.A;
}
function f4() {
const c1 = { a: 1, b: "foo" };
const c2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
let x1 = { a: 1, b: "foo" };
let x2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
}
function f5() {
const c1 = [1, "foo"];
const c2: (1 | "foo")[] = [1, "foo"];
const c3: [1, "foo"] = [1, "foo"];
let x1 = [1, "foo"];
let x2: (1 | "foo")[] = [1, "foo"];
let x3: [1, "foo"] = [1, "foo"];
}
function f6() {
const { c1 = true, c2 = 0, c3 = "foo" } = { c1: false, c2: 1, c3: "bar" };
let { x1 = true, x2 = 0, x3 = "foo" } = { x1: false, x2: 1, x3: "bar" };
}
function f10() {
return "hello";
}
function f11() {
return cond ? 1 : "two";
}
function f12() {
if (cond) {
return 1;
}
else {
return "two";
}
}
class C2 {
foo() {
return 0;
}
bar() {
return cond ? 0 : 1;
}
}
function f20() {
const f1 = () => 0;
const f2 = () => "hello";
const f3 = () => true;
const f4 = () => E.C;
const f5 = (): "foo" => "foo";
const f6: () => "foo" | "bar" = () => "bar";
const f7: (() => "foo") | (() => "bar") = () => "bar";
}
declare function g1<T>(x: T): T;
declare function g2<T>(x: T, y: T): T;
declare function g3<T, U>(x: T, y: U): T | U;
declare function g4<T>(x: T): T[];
declare function g5<T extends number>(x: T, y: T): T[];
declare function g6<T>(x: T[]): T;
declare function g7<T>(x: T[]): T[];
declare function g8<T>(x: T, f: (p: T) => T): T;
const a: (1 | 2)[] = [1, 2];
const x1 = g1(1); // Type 1
const x2 = g2(1, 1); // Type 1
const x3 = g2(1, 2); // Type 1 | 2
const x4 = g3(1, "two"); // Type 1 | "two"
const x5 = g4(1); // Type number[]
const x6 = g5(1, 2); // Type (1 | 2)[]
const x7 = g6([1, 2]); // Type number
const x8 = g6(a); // Type 1 | 2
const x9 = g7(a); // Type (1 | 2)[]
const x10 = g8(1, x => x); // Type number
const x11 = g8(1, x => x + 1); // Type number
function makeArray<T>(x: T): T[] {
return [x];
}
function append<T>(a: T[], x: T): T[] {
let result = a.slice();
result.push(x);
return result;
}
type Bit = 0 | 1;
let aa = makeArray<Bit>(0);
aa = append(aa, 1);
//// [literalTypes2.js]
var E;
(function (E) {
E[E["A"] = 0] = "A";
E[E["B"] = 1] = "B";
E[E["C"] = 2] = "C";
})(E || (E = {}));
var cond;
function f1(p1, p2, p3, p4) {
if (p1 === void 0) { p1 = 1; }
if (p2 === void 0) { p2 = "abc"; }
if (p3 === void 0) { p3 = true; }
if (p4 === void 0) { p4 = E.A; }
var v1 = 1;
var v2 = -123;
var v3 = 3 + 4;
var v4 = "abc";
var v5 = "";
var v6 = "abc" + "def";
var v7 = true;
var v8 = E.A;
var x1 = 1;
var x2 = -123;
var x3 = 3 + 4;
var x4 = "abc";
var x5 = "";
var x6 = "abc" + "def";
var x7 = true;
var x8 = E.A;
var c1 = 1;
var c2 = -123;
var c3 = 3 + 4;
var c4 = "abc";
var c5 = "";
var c6 = "abc" + "def";
var c7 = true;
var c8 = E.A;
}
function f2(p1, p2, p3, p4) {
if (p1 === void 0) { p1 = 1; }
if (p2 === void 0) { p2 = "abc"; }
if (p3 === void 0) { p3 = true; }
if (p4 === void 0) { p4 = E.A; }
var v1 = 1;
var v2 = -123;
var v3 = "abc";
var v4 = true;
var v5 = E.A;
var x1 = 1;
var x2 = -123;
var x3 = "abc";
var x4 = true;
var x5 = E.A;
}
function f3() {
var c1 = cond ? 1 : 2;
var c2 = cond ? 1 : "two";
var c3 = cond ? E.A : cond ? true : 123;
var c4 = cond ? "abc" : null;
var c5 = cond ? 456 : undefined;
var c6 = { kind: 123 };
var c7 = [1, "bar"];
var c8 = cond ? c6 : cond ? c7 : "hello";
var x1 = c1;
var x2 = c2;
var x3 = c3;
var x4 = c4;
var x5 = c5;
var x6 = c6;
var x7 = c7;
var x8 = c8;
}
var C1 = (function () {
function C1() {
this.x1 = 1;
this.x2 = -123;
this.x3 = 3 + 4;
this.x4 = "abc";
this.x5 = "";
this.x6 = "abc" + "def";
this.x7 = true;
this.x8 = E.A;
this.c1 = 1;
this.c2 = -123;
this.c3 = 3 + 4;
this.c4 = "abc";
this.c5 = "";
this.c6 = "abc" + "def";
this.c7 = true;
this.c8 = E.A;
}
return C1;
}());
function f4() {
var c1 = { a: 1, b: "foo" };
var c2 = { a: 1, b: "foo" };
var x1 = { a: 1, b: "foo" };
var x2 = { a: 1, b: "foo" };
}
function f5() {
var c1 = [1, "foo"];
var c2 = [1, "foo"];
var c3 = [1, "foo"];
var x1 = [1, "foo"];
var x2 = [1, "foo"];
var x3 = [1, "foo"];
}
function f6() {
var _a = { c1: false, c2: 1, c3: "bar" }, _b = _a.c1, c1 = _b === void 0 ? true : _b, _c = _a.c2, c2 = _c === void 0 ? 0 : _c, _d = _a.c3, c3 = _d === void 0 ? "foo" : _d;
var _e = { x1: false, x2: 1, x3: "bar" }, _f = _e.x1, x1 = _f === void 0 ? true : _f, _g = _e.x2, x2 = _g === void 0 ? 0 : _g, _h = _e.x3, x3 = _h === void 0 ? "foo" : _h;
}
function f10() {
return "hello";
}
function f11() {
return cond ? 1 : "two";
}
function f12() {
if (cond) {
return 1;
}
else {
return "two";
}
}
var C2 = (function () {
function C2() {
}
C2.prototype.foo = function () {
return 0;
};
C2.prototype.bar = function () {
return cond ? 0 : 1;
};
return C2;
}());
function f20() {
var f1 = function () { return 0; };
var f2 = function () { return "hello"; };
var f3 = function () { return true; };
var f4 = function () { return E.C; };
var f5 = function () { return "foo"; };
var f6 = function () { return "bar"; };
var f7 = function () { return "bar"; };
}
var a = [1, 2];
var x1 = g1(1); // Type 1
var x2 = g2(1, 1); // Type 1
var x3 = g2(1, 2); // Type 1 | 2
var x4 = g3(1, "two"); // Type 1 | "two"
var x5 = g4(1); // Type number[]
var x6 = g5(1, 2); // Type (1 | 2)[]
var x7 = g6([1, 2]); // Type number
var x8 = g6(a); // Type 1 | 2
var x9 = g7(a); // Type (1 | 2)[]
var x10 = g8(1, function (x) { return x; }); // Type number
var x11 = g8(1, function (x) { return x + 1; }); // Type number
function makeArray(x) {
return [x];
}
function append(a, x) {
var result = a.slice();
result.push(x);
return result;
}
var aa = makeArray(0);
aa = append(aa, 1);

View file

@ -0,0 +1,602 @@
=== tests/cases/conformance/types/literal/literalTypes2.ts ===
enum E {
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
A, B, C
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>B : Symbol(E.B, Decl(literalTypes2.ts, 1, 6))
>C : Symbol(E.C, Decl(literalTypes2.ts, 1, 9))
}
let cond: boolean;
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
function f1(p1 = 1, p2 = "abc", p3 = true, p4 = E.A) {
>f1 : Symbol(f1, Decl(literalTypes2.ts, 4, 18))
>p1 : Symbol(p1, Decl(literalTypes2.ts, 6, 12))
>p2 : Symbol(p2, Decl(literalTypes2.ts, 6, 19))
>p3 : Symbol(p3, Decl(literalTypes2.ts, 6, 31))
>p4 : Symbol(p4, Decl(literalTypes2.ts, 6, 42))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
var v1 = 1;
>v1 : Symbol(v1, Decl(literalTypes2.ts, 7, 7))
var v2 = -123;
>v2 : Symbol(v2, Decl(literalTypes2.ts, 8, 7))
var v3 = 3 + 4;
>v3 : Symbol(v3, Decl(literalTypes2.ts, 9, 7))
var v4 = "abc";
>v4 : Symbol(v4, Decl(literalTypes2.ts, 10, 7))
var v5 = "";
>v5 : Symbol(v5, Decl(literalTypes2.ts, 11, 7))
var v6 = "abc" + "def";
>v6 : Symbol(v6, Decl(literalTypes2.ts, 12, 7))
var v7 = true;
>v7 : Symbol(v7, Decl(literalTypes2.ts, 13, 7))
var v8 = E.A;
>v8 : Symbol(v8, Decl(literalTypes2.ts, 14, 7))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
let x1 = 1;
>x1 : Symbol(x1, Decl(literalTypes2.ts, 15, 7))
let x2 = -123;
>x2 : Symbol(x2, Decl(literalTypes2.ts, 16, 7))
let x3 = 3 + 4;
>x3 : Symbol(x3, Decl(literalTypes2.ts, 17, 7))
let x4 = "abc";
>x4 : Symbol(x4, Decl(literalTypes2.ts, 18, 7))
let x5 = "";
>x5 : Symbol(x5, Decl(literalTypes2.ts, 19, 7))
let x6 = "abc" + "def";
>x6 : Symbol(x6, Decl(literalTypes2.ts, 20, 7))
let x7 = true;
>x7 : Symbol(x7, Decl(literalTypes2.ts, 21, 7))
var x8 = E.A;
>x8 : Symbol(x8, Decl(literalTypes2.ts, 22, 7))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
const c1 = 1;
>c1 : Symbol(c1, Decl(literalTypes2.ts, 23, 9))
const c2 = -123;
>c2 : Symbol(c2, Decl(literalTypes2.ts, 24, 9))
const c3 = 3 + 4;
>c3 : Symbol(c3, Decl(literalTypes2.ts, 25, 9))
const c4 = "abc";
>c4 : Symbol(c4, Decl(literalTypes2.ts, 26, 9))
const c5 = "";
>c5 : Symbol(c5, Decl(literalTypes2.ts, 27, 9))
const c6 = "abc" + "def";
>c6 : Symbol(c6, Decl(literalTypes2.ts, 28, 9))
const c7 = true;
>c7 : Symbol(c7, Decl(literalTypes2.ts, 29, 9))
const c8 = E.A;
>c8 : Symbol(c8, Decl(literalTypes2.ts, 30, 9))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
}
function f2(p1: 1 = 1, p2: "abc" = "abc", p3: true = true, p4: E.A = E.A) {
>f2 : Symbol(f2, Decl(literalTypes2.ts, 31, 1))
>p1 : Symbol(p1, Decl(literalTypes2.ts, 33, 12))
>p2 : Symbol(p2, Decl(literalTypes2.ts, 33, 22))
>p3 : Symbol(p3, Decl(literalTypes2.ts, 33, 41))
>p4 : Symbol(p4, Decl(literalTypes2.ts, 33, 58))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
var v1: 1 = 1;
>v1 : Symbol(v1, Decl(literalTypes2.ts, 34, 7))
var v2: -123 = -123;
>v2 : Symbol(v2, Decl(literalTypes2.ts, 35, 7))
var v3: "abc" = "abc";
>v3 : Symbol(v3, Decl(literalTypes2.ts, 36, 7))
var v4: true = true;
>v4 : Symbol(v4, Decl(literalTypes2.ts, 37, 7))
var v5: E.A = E.A;
>v5 : Symbol(v5, Decl(literalTypes2.ts, 38, 7))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
let x1: 1 = 1;
>x1 : Symbol(x1, Decl(literalTypes2.ts, 39, 7))
let x2: -123 = -123;
>x2 : Symbol(x2, Decl(literalTypes2.ts, 40, 7))
let x3: "abc" = "abc";
>x3 : Symbol(x3, Decl(literalTypes2.ts, 41, 7))
let x4: true = true;
>x4 : Symbol(x4, Decl(literalTypes2.ts, 42, 7))
let x5: E.A = E.A;
>x5 : Symbol(x5, Decl(literalTypes2.ts, 43, 7))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
}
function f3() {
>f3 : Symbol(f3, Decl(literalTypes2.ts, 44, 1))
const c1 = cond ? 1 : 2;
>c1 : Symbol(c1, Decl(literalTypes2.ts, 47, 9))
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
const c2 = cond ? 1 : "two";
>c2 : Symbol(c2, Decl(literalTypes2.ts, 48, 9))
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
const c3 = cond ? E.A : cond ? true : 123;
>c3 : Symbol(c3, Decl(literalTypes2.ts, 49, 9))
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
const c4 = cond ? "abc" : null;
>c4 : Symbol(c4, Decl(literalTypes2.ts, 50, 9))
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
const c5 = cond ? 456 : undefined;
>c5 : Symbol(c5, Decl(literalTypes2.ts, 51, 9))
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
>undefined : Symbol(undefined)
const c6: { kind: 123 } = { kind: 123 };
>c6 : Symbol(c6, Decl(literalTypes2.ts, 52, 9))
>kind : Symbol(kind, Decl(literalTypes2.ts, 52, 15))
>kind : Symbol(kind, Decl(literalTypes2.ts, 52, 31))
const c7: [1 | 2, "foo" | "bar"] = [1, "bar"];
>c7 : Symbol(c7, Decl(literalTypes2.ts, 53, 9))
const c8 = cond ? c6 : cond ? c7 : "hello";
>c8 : Symbol(c8, Decl(literalTypes2.ts, 54, 9))
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
>c6 : Symbol(c6, Decl(literalTypes2.ts, 52, 9))
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
>c7 : Symbol(c7, Decl(literalTypes2.ts, 53, 9))
let x1 = c1;
>x1 : Symbol(x1, Decl(literalTypes2.ts, 55, 7))
>c1 : Symbol(c1, Decl(literalTypes2.ts, 47, 9))
let x2 = c2;
>x2 : Symbol(x2, Decl(literalTypes2.ts, 56, 7))
>c2 : Symbol(c2, Decl(literalTypes2.ts, 48, 9))
let x3 = c3;
>x3 : Symbol(x3, Decl(literalTypes2.ts, 57, 7))
>c3 : Symbol(c3, Decl(literalTypes2.ts, 49, 9))
let x4 = c4;
>x4 : Symbol(x4, Decl(literalTypes2.ts, 58, 7))
>c4 : Symbol(c4, Decl(literalTypes2.ts, 50, 9))
let x5 = c5;
>x5 : Symbol(x5, Decl(literalTypes2.ts, 59, 7))
>c5 : Symbol(c5, Decl(literalTypes2.ts, 51, 9))
let x6 = c6;
>x6 : Symbol(x6, Decl(literalTypes2.ts, 60, 7))
>c6 : Symbol(c6, Decl(literalTypes2.ts, 52, 9))
let x7 = c7;
>x7 : Symbol(x7, Decl(literalTypes2.ts, 61, 7))
>c7 : Symbol(c7, Decl(literalTypes2.ts, 53, 9))
let x8 = c8;
>x8 : Symbol(x8, Decl(literalTypes2.ts, 62, 7))
>c8 : Symbol(c8, Decl(literalTypes2.ts, 54, 9))
}
class C1 {
>C1 : Symbol(C1, Decl(literalTypes2.ts, 63, 1))
x1 = 1;
>x1 : Symbol(C1.x1, Decl(literalTypes2.ts, 65, 10))
x2 = -123;
>x2 : Symbol(C1.x2, Decl(literalTypes2.ts, 66, 11))
x3 = 3 + 4;
>x3 : Symbol(C1.x3, Decl(literalTypes2.ts, 67, 14))
x4 = "abc";
>x4 : Symbol(C1.x4, Decl(literalTypes2.ts, 68, 15))
x5 = "";
>x5 : Symbol(C1.x5, Decl(literalTypes2.ts, 69, 15))
x6 = "abc" + "def";
>x6 : Symbol(C1.x6, Decl(literalTypes2.ts, 70, 12))
x7 = true;
>x7 : Symbol(C1.x7, Decl(literalTypes2.ts, 71, 23))
x8 = E.A;
>x8 : Symbol(C1.x8, Decl(literalTypes2.ts, 72, 14))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
readonly c1 = 1;
>c1 : Symbol(C1.c1, Decl(literalTypes2.ts, 73, 13))
readonly c2 = -123;
>c2 : Symbol(C1.c2, Decl(literalTypes2.ts, 74, 20))
readonly c3 = 3 + 4;
>c3 : Symbol(C1.c3, Decl(literalTypes2.ts, 75, 23))
readonly c4 = "abc";
>c4 : Symbol(C1.c4, Decl(literalTypes2.ts, 76, 24))
readonly c5 = "";
>c5 : Symbol(C1.c5, Decl(literalTypes2.ts, 77, 24))
readonly c6 = "abc" + "def";
>c6 : Symbol(C1.c6, Decl(literalTypes2.ts, 78, 21))
readonly c7 = true;
>c7 : Symbol(C1.c7, Decl(literalTypes2.ts, 79, 32))
readonly c8 = E.A;
>c8 : Symbol(C1.c8, Decl(literalTypes2.ts, 80, 23))
>E.A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>A : Symbol(E.A, Decl(literalTypes2.ts, 0, 8))
}
function f4() {
>f4 : Symbol(f4, Decl(literalTypes2.ts, 82, 1))
const c1 = { a: 1, b: "foo" };
>c1 : Symbol(c1, Decl(literalTypes2.ts, 85, 9))
>a : Symbol(a, Decl(literalTypes2.ts, 85, 16))
>b : Symbol(b, Decl(literalTypes2.ts, 85, 22))
const c2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
>c2 : Symbol(c2, Decl(literalTypes2.ts, 86, 9))
>a : Symbol(a, Decl(literalTypes2.ts, 86, 15))
>b : Symbol(b, Decl(literalTypes2.ts, 86, 26))
>a : Symbol(a, Decl(literalTypes2.ts, 86, 49))
>b : Symbol(b, Decl(literalTypes2.ts, 86, 55))
let x1 = { a: 1, b: "foo" };
>x1 : Symbol(x1, Decl(literalTypes2.ts, 87, 7))
>a : Symbol(a, Decl(literalTypes2.ts, 87, 14))
>b : Symbol(b, Decl(literalTypes2.ts, 87, 20))
let x2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
>x2 : Symbol(x2, Decl(literalTypes2.ts, 88, 7))
>a : Symbol(a, Decl(literalTypes2.ts, 88, 13))
>b : Symbol(b, Decl(literalTypes2.ts, 88, 24))
>a : Symbol(a, Decl(literalTypes2.ts, 88, 47))
>b : Symbol(b, Decl(literalTypes2.ts, 88, 53))
}
function f5() {
>f5 : Symbol(f5, Decl(literalTypes2.ts, 89, 1))
const c1 = [1, "foo"];
>c1 : Symbol(c1, Decl(literalTypes2.ts, 92, 9))
const c2: (1 | "foo")[] = [1, "foo"];
>c2 : Symbol(c2, Decl(literalTypes2.ts, 93, 9))
const c3: [1, "foo"] = [1, "foo"];
>c3 : Symbol(c3, Decl(literalTypes2.ts, 94, 9))
let x1 = [1, "foo"];
>x1 : Symbol(x1, Decl(literalTypes2.ts, 95, 7))
let x2: (1 | "foo")[] = [1, "foo"];
>x2 : Symbol(x2, Decl(literalTypes2.ts, 96, 7))
let x3: [1, "foo"] = [1, "foo"];
>x3 : Symbol(x3, Decl(literalTypes2.ts, 97, 7))
}
function f6() {
>f6 : Symbol(f6, Decl(literalTypes2.ts, 98, 1))
const { c1 = true, c2 = 0, c3 = "foo" } = { c1: false, c2: 1, c3: "bar" };
>c1 : Symbol(c1, Decl(literalTypes2.ts, 101, 11))
>c2 : Symbol(c2, Decl(literalTypes2.ts, 101, 22))
>c3 : Symbol(c3, Decl(literalTypes2.ts, 101, 30))
>c1 : Symbol(c1, Decl(literalTypes2.ts, 101, 47))
>c2 : Symbol(c2, Decl(literalTypes2.ts, 101, 58))
>c3 : Symbol(c3, Decl(literalTypes2.ts, 101, 65))
let { x1 = true, x2 = 0, x3 = "foo" } = { x1: false, x2: 1, x3: "bar" };
>x1 : Symbol(x1, Decl(literalTypes2.ts, 102, 9))
>x2 : Symbol(x2, Decl(literalTypes2.ts, 102, 20))
>x3 : Symbol(x3, Decl(literalTypes2.ts, 102, 28))
>x1 : Symbol(x1, Decl(literalTypes2.ts, 102, 45))
>x2 : Symbol(x2, Decl(literalTypes2.ts, 102, 56))
>x3 : Symbol(x3, Decl(literalTypes2.ts, 102, 63))
}
function f10() {
>f10 : Symbol(f10, Decl(literalTypes2.ts, 103, 1))
return "hello";
}
function f11() {
>f11 : Symbol(f11, Decl(literalTypes2.ts, 107, 1))
return cond ? 1 : "two";
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
}
function f12() {
>f12 : Symbol(f12, Decl(literalTypes2.ts, 111, 1))
if (cond) {
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
return 1;
}
else {
return "two";
}
}
class C2 {
>C2 : Symbol(C2, Decl(literalTypes2.ts, 120, 1))
foo() {
>foo : Symbol(C2.foo, Decl(literalTypes2.ts, 122, 10))
return 0;
}
bar() {
>bar : Symbol(C2.bar, Decl(literalTypes2.ts, 125, 5))
return cond ? 0 : 1;
>cond : Symbol(cond, Decl(literalTypes2.ts, 4, 3))
}
}
function f20() {
>f20 : Symbol(f20, Decl(literalTypes2.ts, 129, 1))
const f1 = () => 0;
>f1 : Symbol(f1, Decl(literalTypes2.ts, 132, 9))
const f2 = () => "hello";
>f2 : Symbol(f2, Decl(literalTypes2.ts, 133, 9))
const f3 = () => true;
>f3 : Symbol(f3, Decl(literalTypes2.ts, 134, 9))
const f4 = () => E.C;
>f4 : Symbol(f4, Decl(literalTypes2.ts, 135, 9))
>E.C : Symbol(E.C, Decl(literalTypes2.ts, 1, 9))
>E : Symbol(E, Decl(literalTypes2.ts, 0, 0))
>C : Symbol(E.C, Decl(literalTypes2.ts, 1, 9))
const f5 = (): "foo" => "foo";
>f5 : Symbol(f5, Decl(literalTypes2.ts, 136, 9))
const f6: () => "foo" | "bar" = () => "bar";
>f6 : Symbol(f6, Decl(literalTypes2.ts, 137, 9))
const f7: (() => "foo") | (() => "bar") = () => "bar";
>f7 : Symbol(f7, Decl(literalTypes2.ts, 138, 9))
}
declare function g1<T>(x: T): T;
>g1 : Symbol(g1, Decl(literalTypes2.ts, 139, 1))
>T : Symbol(T, Decl(literalTypes2.ts, 141, 20))
>x : Symbol(x, Decl(literalTypes2.ts, 141, 23))
>T : Symbol(T, Decl(literalTypes2.ts, 141, 20))
>T : Symbol(T, Decl(literalTypes2.ts, 141, 20))
declare function g2<T>(x: T, y: T): T;
>g2 : Symbol(g2, Decl(literalTypes2.ts, 141, 32))
>T : Symbol(T, Decl(literalTypes2.ts, 142, 20))
>x : Symbol(x, Decl(literalTypes2.ts, 142, 23))
>T : Symbol(T, Decl(literalTypes2.ts, 142, 20))
>y : Symbol(y, Decl(literalTypes2.ts, 142, 28))
>T : Symbol(T, Decl(literalTypes2.ts, 142, 20))
>T : Symbol(T, Decl(literalTypes2.ts, 142, 20))
declare function g3<T, U>(x: T, y: U): T | U;
>g3 : Symbol(g3, Decl(literalTypes2.ts, 142, 38))
>T : Symbol(T, Decl(literalTypes2.ts, 143, 20))
>U : Symbol(U, Decl(literalTypes2.ts, 143, 22))
>x : Symbol(x, Decl(literalTypes2.ts, 143, 26))
>T : Symbol(T, Decl(literalTypes2.ts, 143, 20))
>y : Symbol(y, Decl(literalTypes2.ts, 143, 31))
>U : Symbol(U, Decl(literalTypes2.ts, 143, 22))
>T : Symbol(T, Decl(literalTypes2.ts, 143, 20))
>U : Symbol(U, Decl(literalTypes2.ts, 143, 22))
declare function g4<T>(x: T): T[];
>g4 : Symbol(g4, Decl(literalTypes2.ts, 143, 45))
>T : Symbol(T, Decl(literalTypes2.ts, 144, 20))
>x : Symbol(x, Decl(literalTypes2.ts, 144, 23))
>T : Symbol(T, Decl(literalTypes2.ts, 144, 20))
>T : Symbol(T, Decl(literalTypes2.ts, 144, 20))
declare function g5<T extends number>(x: T, y: T): T[];
>g5 : Symbol(g5, Decl(literalTypes2.ts, 144, 34))
>T : Symbol(T, Decl(literalTypes2.ts, 145, 20))
>x : Symbol(x, Decl(literalTypes2.ts, 145, 38))
>T : Symbol(T, Decl(literalTypes2.ts, 145, 20))
>y : Symbol(y, Decl(literalTypes2.ts, 145, 43))
>T : Symbol(T, Decl(literalTypes2.ts, 145, 20))
>T : Symbol(T, Decl(literalTypes2.ts, 145, 20))
declare function g6<T>(x: T[]): T;
>g6 : Symbol(g6, Decl(literalTypes2.ts, 145, 55))
>T : Symbol(T, Decl(literalTypes2.ts, 146, 20))
>x : Symbol(x, Decl(literalTypes2.ts, 146, 23))
>T : Symbol(T, Decl(literalTypes2.ts, 146, 20))
>T : Symbol(T, Decl(literalTypes2.ts, 146, 20))
declare function g7<T>(x: T[]): T[];
>g7 : Symbol(g7, Decl(literalTypes2.ts, 146, 34))
>T : Symbol(T, Decl(literalTypes2.ts, 147, 20))
>x : Symbol(x, Decl(literalTypes2.ts, 147, 23))
>T : Symbol(T, Decl(literalTypes2.ts, 147, 20))
>T : Symbol(T, Decl(literalTypes2.ts, 147, 20))
declare function g8<T>(x: T, f: (p: T) => T): T;
>g8 : Symbol(g8, Decl(literalTypes2.ts, 147, 36))
>T : Symbol(T, Decl(literalTypes2.ts, 148, 20))
>x : Symbol(x, Decl(literalTypes2.ts, 148, 23))
>T : Symbol(T, Decl(literalTypes2.ts, 148, 20))
>f : Symbol(f, Decl(literalTypes2.ts, 148, 28))
>p : Symbol(p, Decl(literalTypes2.ts, 148, 33))
>T : Symbol(T, Decl(literalTypes2.ts, 148, 20))
>T : Symbol(T, Decl(literalTypes2.ts, 148, 20))
>T : Symbol(T, Decl(literalTypes2.ts, 148, 20))
const a: (1 | 2)[] = [1, 2];
>a : Symbol(a, Decl(literalTypes2.ts, 150, 5))
const x1 = g1(1); // Type 1
>x1 : Symbol(x1, Decl(literalTypes2.ts, 152, 5))
>g1 : Symbol(g1, Decl(literalTypes2.ts, 139, 1))
const x2 = g2(1, 1); // Type 1
>x2 : Symbol(x2, Decl(literalTypes2.ts, 153, 5))
>g2 : Symbol(g2, Decl(literalTypes2.ts, 141, 32))
const x3 = g2(1, 2); // Type 1 | 2
>x3 : Symbol(x3, Decl(literalTypes2.ts, 154, 5))
>g2 : Symbol(g2, Decl(literalTypes2.ts, 141, 32))
const x4 = g3(1, "two"); // Type 1 | "two"
>x4 : Symbol(x4, Decl(literalTypes2.ts, 155, 5))
>g3 : Symbol(g3, Decl(literalTypes2.ts, 142, 38))
const x5 = g4(1); // Type number[]
>x5 : Symbol(x5, Decl(literalTypes2.ts, 156, 5))
>g4 : Symbol(g4, Decl(literalTypes2.ts, 143, 45))
const x6 = g5(1, 2); // Type (1 | 2)[]
>x6 : Symbol(x6, Decl(literalTypes2.ts, 157, 5))
>g5 : Symbol(g5, Decl(literalTypes2.ts, 144, 34))
const x7 = g6([1, 2]); // Type number
>x7 : Symbol(x7, Decl(literalTypes2.ts, 158, 5))
>g6 : Symbol(g6, Decl(literalTypes2.ts, 145, 55))
const x8 = g6(a); // Type 1 | 2
>x8 : Symbol(x8, Decl(literalTypes2.ts, 159, 5))
>g6 : Symbol(g6, Decl(literalTypes2.ts, 145, 55))
>a : Symbol(a, Decl(literalTypes2.ts, 150, 5))
const x9 = g7(a); // Type (1 | 2)[]
>x9 : Symbol(x9, Decl(literalTypes2.ts, 160, 5))
>g7 : Symbol(g7, Decl(literalTypes2.ts, 146, 34))
>a : Symbol(a, Decl(literalTypes2.ts, 150, 5))
const x10 = g8(1, x => x); // Type number
>x10 : Symbol(x10, Decl(literalTypes2.ts, 161, 5))
>g8 : Symbol(g8, Decl(literalTypes2.ts, 147, 36))
>x : Symbol(x, Decl(literalTypes2.ts, 161, 17))
>x : Symbol(x, Decl(literalTypes2.ts, 161, 17))
const x11 = g8(1, x => x + 1); // Type number
>x11 : Symbol(x11, Decl(literalTypes2.ts, 162, 5))
>g8 : Symbol(g8, Decl(literalTypes2.ts, 147, 36))
>x : Symbol(x, Decl(literalTypes2.ts, 162, 17))
>x : Symbol(x, Decl(literalTypes2.ts, 162, 17))
function makeArray<T>(x: T): T[] {
>makeArray : Symbol(makeArray, Decl(literalTypes2.ts, 162, 30))
>T : Symbol(T, Decl(literalTypes2.ts, 164, 19))
>x : Symbol(x, Decl(literalTypes2.ts, 164, 22))
>T : Symbol(T, Decl(literalTypes2.ts, 164, 19))
>T : Symbol(T, Decl(literalTypes2.ts, 164, 19))
return [x];
>x : Symbol(x, Decl(literalTypes2.ts, 164, 22))
}
function append<T>(a: T[], x: T): T[] {
>append : Symbol(append, Decl(literalTypes2.ts, 166, 1))
>T : Symbol(T, Decl(literalTypes2.ts, 168, 16))
>a : Symbol(a, Decl(literalTypes2.ts, 168, 19))
>T : Symbol(T, Decl(literalTypes2.ts, 168, 16))
>x : Symbol(x, Decl(literalTypes2.ts, 168, 26))
>T : Symbol(T, Decl(literalTypes2.ts, 168, 16))
>T : Symbol(T, Decl(literalTypes2.ts, 168, 16))
let result = a.slice();
>result : Symbol(result, Decl(literalTypes2.ts, 169, 7))
>a.slice : Symbol(Array.slice, Decl(lib.d.ts, --, --))
>a : Symbol(a, Decl(literalTypes2.ts, 168, 19))
>slice : Symbol(Array.slice, Decl(lib.d.ts, --, --))
result.push(x);
>result.push : Symbol(Array.push, Decl(lib.d.ts, --, --))
>result : Symbol(result, Decl(literalTypes2.ts, 169, 7))
>push : Symbol(Array.push, Decl(lib.d.ts, --, --))
>x : Symbol(x, Decl(literalTypes2.ts, 168, 26))
return result;
>result : Symbol(result, Decl(literalTypes2.ts, 169, 7))
}
type Bit = 0 | 1;
>Bit : Symbol(Bit, Decl(literalTypes2.ts, 172, 1))
let aa = makeArray<Bit>(0);
>aa : Symbol(aa, Decl(literalTypes2.ts, 176, 3))
>makeArray : Symbol(makeArray, Decl(literalTypes2.ts, 162, 30))
>Bit : Symbol(Bit, Decl(literalTypes2.ts, 172, 1))
aa = append(aa, 1);
>aa : Symbol(aa, Decl(literalTypes2.ts, 176, 3))
>append : Symbol(append, Decl(literalTypes2.ts, 166, 1))
>aa : Symbol(aa, Decl(literalTypes2.ts, 176, 3))

View file

@ -0,0 +1,816 @@
=== tests/cases/conformance/types/literal/literalTypes2.ts ===
enum E {
>E : E
A, B, C
>A : E.A
>B : E.B
>C : E.C
}
let cond: boolean;
>cond : boolean
function f1(p1 = 1, p2 = "abc", p3 = true, p4 = E.A) {
>f1 : (p1?: number, p2?: string, p3?: boolean, p4?: E) => void
>p1 : number
>1 : 1
>p2 : string
>"abc" : "abc"
>p3 : boolean
>true : true
>p4 : E
>E.A : E.A
>E : typeof E
>A : E.A
var v1 = 1;
>v1 : number
>1 : 1
var v2 = -123;
>v2 : number
>-123 : -123
>123 : 123
var v3 = 3 + 4;
>v3 : number
>3 + 4 : number
>3 : 3
>4 : 4
var v4 = "abc";
>v4 : string
>"abc" : "abc"
var v5 = "";
>v5 : string
>"" : ""
var v6 = "abc" + "def";
>v6 : string
>"abc" + "def" : string
>"abc" : "abc"
>"def" : "def"
var v7 = true;
>v7 : boolean
>true : true
var v8 = E.A;
>v8 : E
>E.A : E.A
>E : typeof E
>A : E.A
let x1 = 1;
>x1 : number
>1 : 1
let x2 = -123;
>x2 : number
>-123 : -123
>123 : 123
let x3 = 3 + 4;
>x3 : number
>3 + 4 : number
>3 : 3
>4 : 4
let x4 = "abc";
>x4 : string
>"abc" : "abc"
let x5 = "";
>x5 : string
>"" : ""
let x6 = "abc" + "def";
>x6 : string
>"abc" + "def" : string
>"abc" : "abc"
>"def" : "def"
let x7 = true;
>x7 : boolean
>true : true
var x8 = E.A;
>x8 : E
>E.A : E.A
>E : typeof E
>A : E.A
const c1 = 1;
>c1 : 1
>1 : 1
const c2 = -123;
>c2 : -123
>-123 : -123
>123 : 123
const c3 = 3 + 4;
>c3 : number
>3 + 4 : number
>3 : 3
>4 : 4
const c4 = "abc";
>c4 : "abc"
>"abc" : "abc"
const c5 = "";
>c5 : ""
>"" : ""
const c6 = "abc" + "def";
>c6 : string
>"abc" + "def" : string
>"abc" : "abc"
>"def" : "def"
const c7 = true;
>c7 : true
>true : true
const c8 = E.A;
>c8 : E.A
>E.A : E.A
>E : typeof E
>A : E.A
}
function f2(p1: 1 = 1, p2: "abc" = "abc", p3: true = true, p4: E.A = E.A) {
>f2 : (p1?: 1, p2?: "abc", p3?: true, p4?: E.A) => void
>p1 : 1
>1 : 1
>p2 : "abc"
>"abc" : "abc"
>p3 : true
>true : true
>true : true
>p4 : E.A
>E : any
>A : E.A
>E.A : E.A
>E : typeof E
>A : E.A
var v1: 1 = 1;
>v1 : 1
>1 : 1
var v2: -123 = -123;
>v2 : -123
>-123 : -123
>123 : 123
>-123 : -123
>123 : 123
var v3: "abc" = "abc";
>v3 : "abc"
>"abc" : "abc"
var v4: true = true;
>v4 : true
>true : true
>true : true
var v5: E.A = E.A;
>v5 : E.A
>E : any
>A : E.A
>E.A : E.A
>E : typeof E
>A : E.A
let x1: 1 = 1;
>x1 : 1
>1 : 1
let x2: -123 = -123;
>x2 : -123
>-123 : -123
>123 : 123
>-123 : -123
>123 : 123
let x3: "abc" = "abc";
>x3 : "abc"
>"abc" : "abc"
let x4: true = true;
>x4 : true
>true : true
>true : true
let x5: E.A = E.A;
>x5 : E.A
>E : any
>A : E.A
>E.A : E.A
>E : typeof E
>A : E.A
}
function f3() {
>f3 : () => void
const c1 = cond ? 1 : 2;
>c1 : 1 | 2
>cond ? 1 : 2 : 1 | 2
>cond : boolean
>1 : 1
>2 : 2
const c2 = cond ? 1 : "two";
>c2 : 1 | "two"
>cond ? 1 : "two" : 1 | "two"
>cond : boolean
>1 : 1
>"two" : "two"
const c3 = cond ? E.A : cond ? true : 123;
>c3 : true | E.A | 123
>cond ? E.A : cond ? true : 123 : true | E.A | 123
>cond : boolean
>E.A : E.A
>E : typeof E
>A : E.A
>cond ? true : 123 : true | 123
>cond : boolean
>true : true
>123 : 123
const c4 = cond ? "abc" : null;
>c4 : "abc"
>cond ? "abc" : null : "abc"
>cond : boolean
>"abc" : "abc"
>null : null
const c5 = cond ? 456 : undefined;
>c5 : 456
>cond ? 456 : undefined : 456
>cond : boolean
>456 : 456
>undefined : undefined
const c6: { kind: 123 } = { kind: 123 };
>c6 : { kind: 123; }
>kind : 123
>{ kind: 123 } : { kind: 123; }
>kind : number
>123 : 123
const c7: [1 | 2, "foo" | "bar"] = [1, "bar"];
>c7 : [1 | 2, "foo" | "bar"]
>[1, "bar"] : [1, "bar"]
>1 : 1
>"bar" : "bar"
const c8 = cond ? c6 : cond ? c7 : "hello";
>c8 : { kind: 123; } | [1 | 2, "foo" | "bar"] | "hello"
>cond ? c6 : cond ? c7 : "hello" : { kind: 123; } | [1 | 2, "foo" | "bar"] | "hello"
>cond : boolean
>c6 : { kind: 123; }
>cond ? c7 : "hello" : [1 | 2, "foo" | "bar"] | "hello"
>cond : boolean
>c7 : [1 | 2, "foo" | "bar"]
>"hello" : "hello"
let x1 = c1;
>x1 : number
>c1 : 1 | 2
let x2 = c2;
>x2 : string | number
>c2 : 1 | "two"
let x3 = c3;
>x3 : number | boolean | E
>c3 : true | E.A | 123
let x4 = c4;
>x4 : string
>c4 : "abc"
let x5 = c5;
>x5 : number
>c5 : 456
let x6 = c6;
>x6 : { kind: 123; }
>c6 : { kind: 123; }
let x7 = c7;
>x7 : [1 | 2, "foo" | "bar"]
>c7 : [1 | 2, "foo" | "bar"]
let x8 = c8;
>x8 : string | { kind: 123; } | [1 | 2, "foo" | "bar"]
>c8 : { kind: 123; } | [1 | 2, "foo" | "bar"] | "hello"
}
class C1 {
>C1 : C1
x1 = 1;
>x1 : number
>1 : 1
x2 = -123;
>x2 : number
>-123 : -123
>123 : 123
x3 = 3 + 4;
>x3 : number
>3 + 4 : number
>3 : 3
>4 : 4
x4 = "abc";
>x4 : string
>"abc" : "abc"
x5 = "";
>x5 : string
>"" : ""
x6 = "abc" + "def";
>x6 : string
>"abc" + "def" : string
>"abc" : "abc"
>"def" : "def"
x7 = true;
>x7 : boolean
>true : true
x8 = E.A;
>x8 : E
>E.A : E.A
>E : typeof E
>A : E.A
readonly c1 = 1;
>c1 : 1
>1 : 1
readonly c2 = -123;
>c2 : -123
>-123 : -123
>123 : 123
readonly c3 = 3 + 4;
>c3 : number
>3 + 4 : number
>3 : 3
>4 : 4
readonly c4 = "abc";
>c4 : "abc"
>"abc" : "abc"
readonly c5 = "";
>c5 : ""
>"" : ""
readonly c6 = "abc" + "def";
>c6 : string
>"abc" + "def" : string
>"abc" : "abc"
>"def" : "def"
readonly c7 = true;
>c7 : true
>true : true
readonly c8 = E.A;
>c8 : E.A
>E.A : E.A
>E : typeof E
>A : E.A
}
function f4() {
>f4 : () => void
const c1 = { a: 1, b: "foo" };
>c1 : { a: number; b: string; }
>{ a: 1, b: "foo" } : { a: number; b: string; }
>a : number
>1 : 1
>b : string
>"foo" : "foo"
const c2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
>c2 : { a: 0 | 1; b: "foo" | "bar"; }
>a : 0 | 1
>b : "foo" | "bar"
>{ a: 1, b: "foo" } : { a: 1; b: "foo"; }
>a : number
>1 : 1
>b : string
>"foo" : "foo"
let x1 = { a: 1, b: "foo" };
>x1 : { a: number; b: string; }
>{ a: 1, b: "foo" } : { a: number; b: string; }
>a : number
>1 : 1
>b : string
>"foo" : "foo"
let x2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
>x2 : { a: 0 | 1; b: "foo" | "bar"; }
>a : 0 | 1
>b : "foo" | "bar"
>{ a: 1, b: "foo" } : { a: 1; b: "foo"; }
>a : number
>1 : 1
>b : string
>"foo" : "foo"
}
function f5() {
>f5 : () => void
const c1 = [1, "foo"];
>c1 : (string | number)[]
>[1, "foo"] : (string | number)[]
>1 : 1
>"foo" : "foo"
const c2: (1 | "foo")[] = [1, "foo"];
>c2 : (1 | "foo")[]
>[1, "foo"] : (1 | "foo")[]
>1 : 1
>"foo" : "foo"
const c3: [1, "foo"] = [1, "foo"];
>c3 : [1, "foo"]
>[1, "foo"] : [1, "foo"]
>1 : 1
>"foo" : "foo"
let x1 = [1, "foo"];
>x1 : (string | number)[]
>[1, "foo"] : (string | number)[]
>1 : 1
>"foo" : "foo"
let x2: (1 | "foo")[] = [1, "foo"];
>x2 : (1 | "foo")[]
>[1, "foo"] : (1 | "foo")[]
>1 : 1
>"foo" : "foo"
let x3: [1, "foo"] = [1, "foo"];
>x3 : [1, "foo"]
>[1, "foo"] : [1, "foo"]
>1 : 1
>"foo" : "foo"
}
function f6() {
>f6 : () => void
const { c1 = true, c2 = 0, c3 = "foo" } = { c1: false, c2: 1, c3: "bar" };
>c1 : boolean
>true : true
>c2 : 0 | 1
>0 : 0
>c3 : "foo" | "bar"
>"foo" : "foo"
>{ c1: false, c2: 1, c3: "bar" } : { c1?: false; c2?: 1; c3?: "bar"; }
>c1 : boolean
>false : false
>c2 : number
>1 : 1
>c3 : string
>"bar" : "bar"
let { x1 = true, x2 = 0, x3 = "foo" } = { x1: false, x2: 1, x3: "bar" };
>x1 : boolean
>true : true
>x2 : number
>0 : 0
>x3 : string
>"foo" : "foo"
>{ x1: false, x2: 1, x3: "bar" } : { x1?: false; x2?: number; x3?: string; }
>x1 : boolean
>false : false
>x2 : number
>1 : 1
>x3 : string
>"bar" : "bar"
}
function f10() {
>f10 : () => string
return "hello";
>"hello" : "hello"
}
function f11() {
>f11 : () => 1 | "two"
return cond ? 1 : "two";
>cond ? 1 : "two" : 1 | "two"
>cond : boolean
>1 : 1
>"two" : "two"
}
function f12() {
>f12 : () => 1 | "two"
if (cond) {
>cond : boolean
return 1;
>1 : 1
}
else {
return "two";
>"two" : "two"
}
}
class C2 {
>C2 : C2
foo() {
>foo : () => number
return 0;
>0 : 0
}
bar() {
>bar : () => 0 | 1
return cond ? 0 : 1;
>cond ? 0 : 1 : 0 | 1
>cond : boolean
>0 : 0
>1 : 1
}
}
function f20() {
>f20 : () => void
const f1 = () => 0;
>f1 : () => number
>() => 0 : () => number
>0 : 0
const f2 = () => "hello";
>f2 : () => string
>() => "hello" : () => string
>"hello" : "hello"
const f3 = () => true;
>f3 : () => boolean
>() => true : () => boolean
>true : true
const f4 = () => E.C;
>f4 : () => E
>() => E.C : () => E
>E.C : E.C
>E : typeof E
>C : E.C
const f5 = (): "foo" => "foo";
>f5 : () => "foo"
>(): "foo" => "foo" : () => "foo"
>"foo" : "foo"
const f6: () => "foo" | "bar" = () => "bar";
>f6 : () => "foo" | "bar"
>() => "bar" : () => "bar"
>"bar" : "bar"
const f7: (() => "foo") | (() => "bar") = () => "bar";
>f7 : (() => "foo") | (() => "bar")
>() => "bar" : () => "bar"
>"bar" : "bar"
}
declare function g1<T>(x: T): T;
>g1 : <T>(x: T) => T
>T : T
>x : T
>T : T
>T : T
declare function g2<T>(x: T, y: T): T;
>g2 : <T>(x: T, y: T) => T
>T : T
>x : T
>T : T
>y : T
>T : T
>T : T
declare function g3<T, U>(x: T, y: U): T | U;
>g3 : <T, U>(x: T, y: U) => T | U
>T : T
>U : U
>x : T
>T : T
>y : U
>U : U
>T : T
>U : U
declare function g4<T>(x: T): T[];
>g4 : <T>(x: T) => T[]
>T : T
>x : T
>T : T
>T : T
declare function g5<T extends number>(x: T, y: T): T[];
>g5 : <T extends number>(x: T, y: T) => T[]
>T : T
>x : T
>T : T
>y : T
>T : T
>T : T
declare function g6<T>(x: T[]): T;
>g6 : <T>(x: T[]) => T
>T : T
>x : T[]
>T : T
>T : T
declare function g7<T>(x: T[]): T[];
>g7 : <T>(x: T[]) => T[]
>T : T
>x : T[]
>T : T
>T : T
declare function g8<T>(x: T, f: (p: T) => T): T;
>g8 : <T>(x: T, f: (p: T) => T) => T
>T : T
>x : T
>T : T
>f : (p: T) => T
>p : T
>T : T
>T : T
>T : T
const a: (1 | 2)[] = [1, 2];
>a : (1 | 2)[]
>[1, 2] : (1 | 2)[]
>1 : 1
>2 : 2
const x1 = g1(1); // Type 1
>x1 : 1
>g1(1) : 1
>g1 : <T>(x: T) => T
>1 : 1
const x2 = g2(1, 1); // Type 1
>x2 : 1
>g2(1, 1) : 1
>g2 : <T>(x: T, y: T) => T
>1 : 1
>1 : 1
const x3 = g2(1, 2); // Type 1 | 2
>x3 : 1 | 2
>g2(1, 2) : 1 | 2
>g2 : <T>(x: T, y: T) => T
>1 : 1
>2 : 2
const x4 = g3(1, "two"); // Type 1 | "two"
>x4 : 1 | "two"
>g3(1, "two") : 1 | "two"
>g3 : <T, U>(x: T, y: U) => T | U
>1 : 1
>"two" : "two"
const x5 = g4(1); // Type number[]
>x5 : number[]
>g4(1) : number[]
>g4 : <T>(x: T) => T[]
>1 : 1
const x6 = g5(1, 2); // Type (1 | 2)[]
>x6 : (1 | 2)[]
>g5(1, 2) : (1 | 2)[]
>g5 : <T extends number>(x: T, y: T) => T[]
>1 : 1
>2 : 2
const x7 = g6([1, 2]); // Type number
>x7 : number
>g6([1, 2]) : number
>g6 : <T>(x: T[]) => T
>[1, 2] : number[]
>1 : 1
>2 : 2
const x8 = g6(a); // Type 1 | 2
>x8 : 1 | 2
>g6(a) : 1 | 2
>g6 : <T>(x: T[]) => T
>a : (1 | 2)[]
const x9 = g7(a); // Type (1 | 2)[]
>x9 : (1 | 2)[]
>g7(a) : (1 | 2)[]
>g7 : <T>(x: T[]) => T[]
>a : (1 | 2)[]
const x10 = g8(1, x => x); // Type number
>x10 : number
>g8(1, x => x) : number
>g8 : <T>(x: T, f: (p: T) => T) => T
>1 : 1
>x => x : (x: number) => number
>x : number
>x : number
const x11 = g8(1, x => x + 1); // Type number
>x11 : number
>g8(1, x => x + 1) : number
>g8 : <T>(x: T, f: (p: T) => T) => T
>1 : 1
>x => x + 1 : (x: number) => number
>x : number
>x + 1 : number
>x : number
>1 : 1
function makeArray<T>(x: T): T[] {
>makeArray : <T>(x: T) => T[]
>T : T
>x : T
>T : T
>T : T
return [x];
>[x] : T[]
>x : T
}
function append<T>(a: T[], x: T): T[] {
>append : <T>(a: T[], x: T) => T[]
>T : T
>a : T[]
>T : T
>x : T
>T : T
>T : T
let result = a.slice();
>result : T[]
>a.slice() : T[]
>a.slice : (start?: number, end?: number) => T[]
>a : T[]
>slice : (start?: number, end?: number) => T[]
result.push(x);
>result.push(x) : number
>result.push : (...items: T[]) => number
>result : T[]
>push : (...items: T[]) => number
>x : T
return result;
>result : T[]
}
type Bit = 0 | 1;
>Bit : 0 | 1
let aa = makeArray<Bit>(0);
>aa : (0 | 1)[]
>makeArray<Bit>(0) : (0 | 1)[]
>makeArray : <T>(x: T) => T[]
>Bit : 0 | 1
>0 : 0
aa = append(aa, 1);
>aa = append(aa, 1) : (0 | 1)[]
>aa : (0 | 1)[]
>append(aa, 1) : (0 | 1)[]
>append : <T>(a: T[], x: T) => T[]
>aa : (0 | 1)[]
>1 : 1

View file

@ -0,0 +1,178 @@
enum E {
A, B, C
}
let cond: boolean;
function f1(p1 = 1, p2 = "abc", p3 = true, p4 = E.A) {
var v1 = 1;
var v2 = -123;
var v3 = 3 + 4;
var v4 = "abc";
var v5 = "";
var v6 = "abc" + "def";
var v7 = true;
var v8 = E.A;
let x1 = 1;
let x2 = -123;
let x3 = 3 + 4;
let x4 = "abc";
let x5 = "";
let x6 = "abc" + "def";
let x7 = true;
var x8 = E.A;
const c1 = 1;
const c2 = -123;
const c3 = 3 + 4;
const c4 = "abc";
const c5 = "";
const c6 = "abc" + "def";
const c7 = true;
const c8 = E.A;
}
function f2(p1: 1 = 1, p2: "abc" = "abc", p3: true = true, p4: E.A = E.A) {
var v1: 1 = 1;
var v2: -123 = -123;
var v3: "abc" = "abc";
var v4: true = true;
var v5: E.A = E.A;
let x1: 1 = 1;
let x2: -123 = -123;
let x3: "abc" = "abc";
let x4: true = true;
let x5: E.A = E.A;
}
function f3() {
const c1 = cond ? 1 : 2;
const c2 = cond ? 1 : "two";
const c3 = cond ? E.A : cond ? true : 123;
const c4 = cond ? "abc" : null;
const c5 = cond ? 456 : undefined;
const c6: { kind: 123 } = { kind: 123 };
const c7: [1 | 2, "foo" | "bar"] = [1, "bar"];
const c8 = cond ? c6 : cond ? c7 : "hello";
let x1 = c1;
let x2 = c2;
let x3 = c3;
let x4 = c4;
let x5 = c5;
let x6 = c6;
let x7 = c7;
let x8 = c8;
}
class C1 {
x1 = 1;
x2 = -123;
x3 = 3 + 4;
x4 = "abc";
x5 = "";
x6 = "abc" + "def";
x7 = true;
x8 = E.A;
readonly c1 = 1;
readonly c2 = -123;
readonly c3 = 3 + 4;
readonly c4 = "abc";
readonly c5 = "";
readonly c6 = "abc" + "def";
readonly c7 = true;
readonly c8 = E.A;
}
function f4() {
const c1 = { a: 1, b: "foo" };
const c2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
let x1 = { a: 1, b: "foo" };
let x2: { a : 0 | 1, b: "foo" | "bar" } = { a: 1, b: "foo" };
}
function f5() {
const c1 = [1, "foo"];
const c2: (1 | "foo")[] = [1, "foo"];
const c3: [1, "foo"] = [1, "foo"];
let x1 = [1, "foo"];
let x2: (1 | "foo")[] = [1, "foo"];
let x3: [1, "foo"] = [1, "foo"];
}
function f6() {
const { c1 = true, c2 = 0, c3 = "foo" } = { c1: false, c2: 1, c3: "bar" };
let { x1 = true, x2 = 0, x3 = "foo" } = { x1: false, x2: 1, x3: "bar" };
}
function f10() {
return "hello";
}
function f11() {
return cond ? 1 : "two";
}
function f12() {
if (cond) {
return 1;
}
else {
return "two";
}
}
class C2 {
foo() {
return 0;
}
bar() {
return cond ? 0 : 1;
}
}
function f20() {
const f1 = () => 0;
const f2 = () => "hello";
const f3 = () => true;
const f4 = () => E.C;
const f5 = (): "foo" => "foo";
const f6: () => "foo" | "bar" = () => "bar";
const f7: (() => "foo") | (() => "bar") = () => "bar";
}
declare function g1<T>(x: T): T;
declare function g2<T>(x: T, y: T): T;
declare function g3<T, U>(x: T, y: U): T | U;
declare function g4<T>(x: T): T[];
declare function g5<T extends number>(x: T, y: T): T[];
declare function g6<T>(x: T[]): T;
declare function g7<T>(x: T[]): T[];
declare function g8<T>(x: T, f: (p: T) => T): T;
const a: (1 | 2)[] = [1, 2];
const x1 = g1(1); // Type 1
const x2 = g2(1, 1); // Type 1
const x3 = g2(1, 2); // Type 1 | 2
const x4 = g3(1, "two"); // Type 1 | "two"
const x5 = g4(1); // Type number[]
const x6 = g5(1, 2); // Type (1 | 2)[]
const x7 = g6([1, 2]); // Type number
const x8 = g6(a); // Type 1 | 2
const x9 = g7(a); // Type (1 | 2)[]
const x10 = g8(1, x => x); // Type number
const x11 = g8(1, x => x + 1); // Type number
function makeArray<T>(x: T): T[] {
return [x];
}
function append<T>(a: T[], x: T): T[] {
let result = a.slice();
result.push(x);
return result;
}
type Bit = 0 | 1;
let aa = makeArray<Bit>(0);
aa = append(aa, 1);