1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
tests/cases/conformance/types/tuple/indexerWithTuple.ts(11,25): error TS2493: Tuple type '[string, number]' of length '2' has no element at index '2'.
tests/cases/conformance/types/tuple/indexerWithTuple.ts(17,27): error TS2493: Tuple type '[number, [string, number]]' of length '2' has no element at index '2'.
tests/cases/conformance/types/tuple/indexerWithTuple.ts(18,25): error TS2514: A tuple type cannot be indexed with a negative value.
tests/cases/conformance/types/tuple/indexerWithTuple.ts(22,30): error TS2493: Tuple type '[number, string | number]' of length '2' has no element at index '2'.
tests/cases/conformance/types/tuple/indexerWithTuple.ts(30,30): error TS2493: Tuple type '[boolean, string | number]' of length '2' has no element at index '2'.
tests/cases/conformance/types/tuple/indexerWithTuple.ts(38,28): error TS2514: A tuple type cannot be indexed with a negative value.
==== tests/cases/conformance/types/tuple/indexerWithTuple.ts (6 errors) ====
var strNumTuple: [string, number] = ["foo", 10];
var numTupleTuple: [number, [string, number]] = [10, ["bar", 20]];
var unionTuple1: [number, string| number] = [10, "foo"];
var unionTuple2: [boolean, string| number] = [true, "foo"];
// no error
var idx0 = 0;
var idx1 = 1;
var ele10 = strNumTuple[0]; // string
var ele11 = strNumTuple[1]; // number
var ele12 = strNumTuple[2]; // string | number
~
!!! error TS2493: Tuple type '[string, number]' of length '2' has no element at index '2'.
var ele13 = strNumTuple[idx0]; // string | number
var ele14 = strNumTuple[idx1]; // string | number
var ele15 = strNumTuple["0"]; // string
var ele16 = strNumTuple["1"]; // number
var strNumTuple1 = numTupleTuple[1]; //[string, number];
var ele17 = numTupleTuple[2]; // number | [string, number]
~
!!! error TS2493: Tuple type '[number, [string, number]]' of length '2' has no element at index '2'.
var ele19 = strNumTuple[-1] // undefined
~~
!!! error TS2514: A tuple type cannot be indexed with a negative value.
var eleUnion10 = unionTuple1[0]; // number
var eleUnion11 = unionTuple1[1]; // string | number
var eleUnion12 = unionTuple1[2]; // string | number
~
!!! error TS2493: Tuple type '[number, string | number]' of length '2' has no element at index '2'.
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
~
!!! error TS2493: Tuple type '[boolean, string | number]' of length '2' has no element at index '2'.
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
type t1 = [string, number][0]; // string
type t2 = [string, number][1]; // number
type t3 = [string, number][-1]; // undefined
~~
!!! error TS2514: A tuple type cannot be indexed with a negative value.
|