2014-07-13 01:04:16 +02:00
|
|
|
//// [arrayLiterals.ts]
|
|
|
|
// Empty array literal with no contextual type has type Undefined[]
|
|
|
|
|
|
|
|
var arr1= [[], [1], ['']];
|
|
|
|
|
|
|
|
var arr2 = [[null], [1], ['']];
|
|
|
|
|
|
|
|
|
|
|
|
// Array literal with elements of only EveryType E has type E[]
|
|
|
|
var stringArrArr = [[''], [""]];
|
|
|
|
|
|
|
|
var stringArr = ['', ""];
|
|
|
|
|
|
|
|
var numberArr = [0, 0.0, 0x00, 1e1];
|
|
|
|
|
|
|
|
var boolArr = [false, true, false, true];
|
|
|
|
|
|
|
|
class C { private p; }
|
|
|
|
var classArr = [new C(), new C()];
|
|
|
|
|
|
|
|
var classTypeArray = [C, C, C];
|
|
|
|
var classTypeArray: Array<typeof C>; // Should OK, not be a parse error
|
|
|
|
|
|
|
|
// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
|
|
|
|
var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
|
|
|
|
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
|
|
|
|
|
|
|
|
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
|
|
|
|
class Base { private p; }
|
|
|
|
class Derived1 extends Base { private m };
|
|
|
|
class Derived2 extends Base { private n };
|
|
|
|
var context3: Base[] = [new Derived1(), new Derived2()];
|
|
|
|
|
|
|
|
// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[]
|
|
|
|
var context4: Base[] = [new Derived1(), new Derived1()];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// [arrayLiterals.js]
|
2014-08-19 19:43:13 +02:00
|
|
|
// Empty array literal with no contextual type has type Undefined[]
|
2014-07-13 01:04:16 +02:00
|
|
|
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 arr1 = [[], [1], ['']];
|
|
|
|
var arr2 = [[null], [1], ['']];
|
2014-08-12 00:54:12 +02:00
|
|
|
// Array literal with elements of only EveryType E has type E[]
|
2014-07-13 01:04:16 +02:00
|
|
|
var stringArrArr = [[''], [""]];
|
|
|
|
var stringArr = ['', ""];
|
|
|
|
var numberArr = [0, 0.0, 0x00, 1e1];
|
|
|
|
var boolArr = [false, true, false, true];
|
|
|
|
var C = (function () {
|
|
|
|
function C() {
|
|
|
|
}
|
|
|
|
return C;
|
|
|
|
})();
|
|
|
|
var classArr = [new C(), new C()];
|
|
|
|
var classTypeArray = [C, C, C];
|
2014-08-15 22:18:54 +02:00
|
|
|
var classTypeArray; // Should OK, not be a parse error
|
2014-08-12 00:54:12 +02:00
|
|
|
// Contextual type C with numeric index signature makes array literal of EveryType E of type BCT(E,C)[]
|
2014-07-13 01:04:16 +02:00
|
|
|
var context1 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
|
|
|
|
var context2 = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }];
|
2014-08-14 15:42:18 +02:00
|
|
|
// Contextual type C with numeric index signature of type Base makes array literal of Derived have type Base[]
|
2014-07-13 01:04:16 +02:00
|
|
|
var Base = (function () {
|
|
|
|
function Base() {
|
|
|
|
}
|
|
|
|
return Base;
|
|
|
|
})();
|
|
|
|
var Derived1 = (function (_super) {
|
|
|
|
__extends(Derived1, _super);
|
|
|
|
function Derived1() {
|
|
|
|
_super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
return Derived1;
|
|
|
|
})(Base);
|
|
|
|
;
|
|
|
|
var Derived2 = (function (_super) {
|
|
|
|
__extends(Derived2, _super);
|
|
|
|
function Derived2() {
|
|
|
|
_super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
return Derived2;
|
|
|
|
})(Base);
|
|
|
|
;
|
|
|
|
var context3 = [new Derived1(), new Derived2()];
|
2014-08-12 00:54:12 +02:00
|
|
|
// Contextual type C with numeric index signature of type Base makes array literal of Derived1 and Derived2 have type Base[]
|
2014-07-13 01:04:16 +02:00
|
|
|
var context4 = [new Derived1(), new Derived1()];
|