2014-10-10 23:23:12 +02:00
|
|
|
//// [indexerWithTuple.ts]
|
2014-10-04 02:37:29 +02:00
|
|
|
var strNumTuple: [string, number] = ["foo", 10];
|
|
|
|
var numTupleTuple: [number, [string, number]] = [10, ["bar", 20]];
|
2014-11-03 18:06:40 +01:00
|
|
|
var unionTuple1: [number, string| number] = [10, "foo"];
|
|
|
|
var unionTuple2: [boolean, string| number] = [true, "foo"];
|
2014-10-04 02:37:29 +02:00
|
|
|
|
|
|
|
// no error
|
|
|
|
var idx0 = 0;
|
|
|
|
var idx1 = 1;
|
|
|
|
var ele10 = strNumTuple[0]; // string
|
|
|
|
var ele11 = strNumTuple[1]; // number
|
2014-11-03 18:06:40 +01:00
|
|
|
var ele12 = strNumTuple[2]; // string | number
|
|
|
|
var ele13 = strNumTuple[idx0]; // string | number
|
|
|
|
var ele14 = strNumTuple[idx1]; // string | number
|
2014-10-04 02:37:29 +02:00
|
|
|
var ele15 = strNumTuple["0"]; // string
|
|
|
|
var ele16 = strNumTuple["1"]; // number
|
|
|
|
var strNumTuple1 = numTupleTuple[1]; //[string, number];
|
2014-11-03 18:06:40 +01:00
|
|
|
var ele17 = numTupleTuple[2]; // number | [string, number]
|
|
|
|
var eleUnion10 = unionTuple1[0]; // number
|
|
|
|
var eleUnion11 = unionTuple1[1]; // string | number
|
|
|
|
var eleUnion12 = unionTuple1[2]; // string | number
|
|
|
|
var eleUnion13 = unionTuple1[idx0]; // string | number
|
|
|
|
var eleUnion14 = unionTuple1[idx1]; // string | number
|
|
|
|
var eleUnion15 = unionTuple1["0"]; // number
|
|
|
|
var eleUnion16 = unionTuple1["1"]; // string | number
|
|
|
|
|
|
|
|
var eleUnion20 = unionTuple2[0]; // boolean
|
|
|
|
var eleUnion21 = unionTuple2[1]; // string | number
|
|
|
|
var eleUnion22 = unionTuple2[2]; // string | number | boolean
|
|
|
|
var eleUnion23 = unionTuple2[idx0]; // string | number | boolean
|
|
|
|
var eleUnion24 = unionTuple2[idx1]; // string | number | boolean
|
|
|
|
var eleUnion25 = unionTuple2["0"]; // boolean
|
|
|
|
var eleUnion26 = unionTuple2["1"]; // string | number
|
2014-10-10 23:23:12 +02:00
|
|
|
|
|
|
|
//// [indexerWithTuple.js]
|
|
|
|
var strNumTuple = ["foo", 10];
|
|
|
|
var numTupleTuple = [10, ["bar", 20]];
|
2014-11-03 18:06:40 +01:00
|
|
|
var unionTuple1 = [10, "foo"];
|
|
|
|
var unionTuple2 = [true, "foo"];
|
2014-10-10 23:23:12 +02:00
|
|
|
// no error
|
|
|
|
var idx0 = 0;
|
|
|
|
var idx1 = 1;
|
|
|
|
var ele10 = strNumTuple[0]; // string
|
|
|
|
var ele11 = strNumTuple[1]; // number
|
2014-11-03 18:06:40 +01:00
|
|
|
var ele12 = strNumTuple[2]; // string | number
|
|
|
|
var ele13 = strNumTuple[idx0]; // string | number
|
|
|
|
var ele14 = strNumTuple[idx1]; // string | number
|
2014-10-10 23:23:12 +02:00
|
|
|
var ele15 = strNumTuple["0"]; // string
|
|
|
|
var ele16 = strNumTuple["1"]; // number
|
|
|
|
var strNumTuple1 = numTupleTuple[1]; //[string, number];
|
2014-11-03 18:06:40 +01:00
|
|
|
var ele17 = numTupleTuple[2]; // number | [string, number]
|
|
|
|
var eleUnion10 = unionTuple1[0]; // number
|
|
|
|
var eleUnion11 = unionTuple1[1]; // string | number
|
|
|
|
var eleUnion12 = unionTuple1[2]; // string | number
|
|
|
|
var eleUnion13 = unionTuple1[idx0]; // string | number
|
|
|
|
var eleUnion14 = unionTuple1[idx1]; // string | number
|
|
|
|
var eleUnion15 = unionTuple1["0"]; // number
|
|
|
|
var eleUnion16 = unionTuple1["1"]; // string | number
|
|
|
|
var eleUnion20 = unionTuple2[0]; // boolean
|
|
|
|
var eleUnion21 = unionTuple2[1]; // string | number
|
|
|
|
var eleUnion22 = unionTuple2[2]; // string | number | boolean
|
|
|
|
var eleUnion23 = unionTuple2[idx0]; // string | number | boolean
|
|
|
|
var eleUnion24 = unionTuple2[idx1]; // string | number | boolean
|
|
|
|
var eleUnion25 = unionTuple2["0"]; // boolean
|
|
|
|
var eleUnion26 = unionTuple2["1"]; // string | number
|