2014-10-10 23:23:12 +02:00
|
|
|
//// [castingTuple.ts]
|
2014-10-04 02:37:29 +02:00
|
|
|
interface I { }
|
|
|
|
class A { a = 10; }
|
|
|
|
class C implements I { c };
|
|
|
|
class D implements I { d };
|
|
|
|
class E extends A { e };
|
|
|
|
class F extends A { f };
|
|
|
|
enum E1 { one }
|
|
|
|
enum E2 { one }
|
|
|
|
|
|
|
|
// no error
|
|
|
|
var numStrTuple: [number, string] = [5, "foo"];
|
|
|
|
var emptyObjTuple = <[{}, {}]>numStrTuple;
|
|
|
|
var numStrBoolTuple = <[number, string, boolean]>numStrTuple;
|
|
|
|
var classCDTuple: [C, D] = [new C(), new D()];
|
|
|
|
var interfaceIITuple = <[I, I]>classCDTuple;
|
|
|
|
var classCDATuple = <[C, D, A]>classCDTuple;
|
|
|
|
var eleFromCDA1 = classCDATuple[2]; // A
|
2014-11-03 18:06:40 +01:00
|
|
|
var eleFromCDA2 = classCDATuple[5]; // C | D | A
|
2014-10-04 02:37:29 +02:00
|
|
|
var t10: [E1, E2] = [E1.one, E2.one];
|
|
|
|
var t11 = <[number, number]>t10;
|
|
|
|
var array1 = <{}[]>emptyObjTuple;
|
2014-11-03 18:06:40 +01:00
|
|
|
var unionTuple: [C, string | number] = [new C(), "foo"];
|
|
|
|
var unionTuple2: [C, string | number, D] = [new C(), "foo", new D()];
|
|
|
|
var unionTuple3: [number, string| number] = [10, "foo"];
|
|
|
|
var unionTuple4 = <[number, number]>unionTuple3;
|
2014-10-04 02:37:29 +02:00
|
|
|
|
|
|
|
// error
|
|
|
|
var t3 = <[number, number]>numStrTuple;
|
|
|
|
var t9 = <[A, I]>classCDTuple;
|
|
|
|
var array1 = <number[]>numStrTuple;
|
2014-11-03 18:06:40 +01:00
|
|
|
t4[2] = 10;
|
|
|
|
|
2014-10-10 23:23:12 +02:00
|
|
|
|
|
|
|
//// [castingTuple.js]
|
|
|
|
var __extends = this.__extends || function (d, b) {
|
|
|
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
|
|
function __() { this.constructor = d; }
|
|
|
|
__.prototype = b.prototype;
|
|
|
|
d.prototype = new __();
|
|
|
|
};
|
|
|
|
var A = (function () {
|
|
|
|
function A() {
|
|
|
|
this.a = 10;
|
|
|
|
}
|
|
|
|
return A;
|
|
|
|
})();
|
|
|
|
var C = (function () {
|
|
|
|
function C() {
|
|
|
|
}
|
|
|
|
return C;
|
|
|
|
})();
|
|
|
|
;
|
|
|
|
var D = (function () {
|
|
|
|
function D() {
|
|
|
|
}
|
|
|
|
return D;
|
|
|
|
})();
|
|
|
|
;
|
|
|
|
var E = (function (_super) {
|
|
|
|
__extends(E, _super);
|
|
|
|
function E() {
|
|
|
|
_super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
return E;
|
|
|
|
})(A);
|
|
|
|
;
|
|
|
|
var F = (function (_super) {
|
|
|
|
__extends(F, _super);
|
|
|
|
function F() {
|
|
|
|
_super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
return F;
|
|
|
|
})(A);
|
|
|
|
;
|
|
|
|
var E1;
|
|
|
|
(function (E1) {
|
|
|
|
E1[E1["one"] = 0] = "one";
|
|
|
|
})(E1 || (E1 = {}));
|
|
|
|
var E2;
|
|
|
|
(function (E2) {
|
|
|
|
E2[E2["one"] = 0] = "one";
|
|
|
|
})(E2 || (E2 = {}));
|
|
|
|
// no error
|
|
|
|
var numStrTuple = [5, "foo"];
|
|
|
|
var emptyObjTuple = numStrTuple;
|
|
|
|
var numStrBoolTuple = numStrTuple;
|
|
|
|
var classCDTuple = [new C(), new D()];
|
|
|
|
var interfaceIITuple = classCDTuple;
|
|
|
|
var classCDATuple = classCDTuple;
|
|
|
|
var eleFromCDA1 = classCDATuple[2]; // A
|
2014-11-03 18:06:40 +01:00
|
|
|
var eleFromCDA2 = classCDATuple[5]; // C | D | A
|
2014-10-10 23:23:12 +02:00
|
|
|
var t10 = [0 /* one */, 0 /* one */];
|
|
|
|
var t11 = t10;
|
|
|
|
var array1 = emptyObjTuple;
|
2014-11-03 18:06:40 +01:00
|
|
|
var unionTuple = [new C(), "foo"];
|
|
|
|
var unionTuple2 = [new C(), "foo", new D()];
|
|
|
|
var unionTuple3 = [10, "foo"];
|
|
|
|
var unionTuple4 = unionTuple3;
|
2014-10-10 23:23:12 +02:00
|
|
|
// error
|
|
|
|
var t3 = numStrTuple;
|
|
|
|
var t9 = classCDTuple;
|
|
|
|
var array1 = numStrTuple;
|
|
|
|
t4[2] = 10;
|