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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
tests/cases/compiler/tupleTypes.ts(11,12): error TS2493: Tuple type '[number, string]' of length '2' has no element at index '2'.
tests/cases/compiler/tupleTypes.ts(12,5): error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type 'undefined', but here has type 'string | number'.
tests/cases/compiler/tupleTypes.ts(14,1): error TS2322: Type '[]' is not assignable to type '[number, string]'.
Source has 0 element(s) but target requires 2.
tests/cases/compiler/tupleTypes.ts(15,1): error TS2322: Type '[number]' is not assignable to type '[number, string]'.
Source has 1 element(s) but target requires 2.
tests/cases/compiler/tupleTypes.ts(17,6): error TS2322: Type 'string' is not assignable to type 'number'.
tests/cases/compiler/tupleTypes.ts(17,15): error TS2322: Type 'number' is not assignable to type 'string'.
tests/cases/compiler/tupleTypes.ts(18,1): error TS2322: Type '[number, string, number]' is not assignable to type '[number, string]'.
Source has 3 element(s) but target allows only 2.
tests/cases/compiler/tupleTypes.ts(35,14): error TS2493: Tuple type '[number, string]' of length '2' has no element at index '2'.
tests/cases/compiler/tupleTypes.ts(36,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'tt2' must be of type 'undefined', but here has type 'string | number'.
tests/cases/compiler/tupleTypes.ts(41,1): error TS2322: Type '[]' is not assignable to type '[number, string]'.
tests/cases/compiler/tupleTypes.ts(47,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]'.
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/tupleTypes.ts(49,1): error TS2322: Type '[number, {}]' is not assignable to type 'number[]'.
Type 'number | {}' is not assignable to type 'number'.
Type '{}' is not assignable to type 'number'.
tests/cases/compiler/tupleTypes.ts(50,1): error TS2322: Type '[number, number]' is not assignable to type '[number, string]'.
Type at position 1 in source is not compatible with type at position 1 in target.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is not assignable to type '[number, string]'.
Type at position 1 in source is not compatible with type at position 1 in target.
Type '{}' is not assignable to type 'string'.
tests/cases/compiler/tupleTypes.ts(57,1): error TS2322: Type '0' is not assignable to type '1'.
tests/cases/compiler/tupleTypes.ts(59,4): error TS2540: Cannot assign to 'length' because it is a read-only property.
tests/cases/compiler/tupleTypes.ts(61,4): error TS2540: Cannot assign to 'length' because it is a read-only property.
tests/cases/compiler/tupleTypes.ts(63,4): error TS2540: Cannot assign to 'length' because it is a read-only property.
==== tests/cases/compiler/tupleTypes.ts (18 errors) ====
var v1: []; // Error
var v2: [number];
var v3: [number, string];
var v4: [number, [string, string]];
var t: [number, string];
var t0 = t[0]; // number
var t0: number;
var t1 = t[1]; // string
var t1: string;
var t2 = t[2]; // number|string
~
!!! error TS2493: Tuple type '[number, string]' of length '2' has no element at index '2'.
var t2: number|string;
~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type 'undefined', but here has type 'string | number'.
!!! related TS6203 tests/cases/compiler/tupleTypes.ts:11:5: 't2' was also declared here.
t = []; // Error
~
!!! error TS2322: Type '[]' is not assignable to type '[number, string]'.
!!! error TS2322: Source has 0 element(s) but target requires 2.
t = [1]; // Error
~
!!! error TS2322: Type '[number]' is not assignable to type '[number, string]'.
!!! error TS2322: Source has 1 element(s) but target requires 2.
t = [1, "hello"]; // Ok
t = ["hello", 1]; // Error
~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
t = [1, "hello", 2]; // Error
~
!!! error TS2322: Type '[number, string, number]' is not assignable to type '[number, string]'.
!!! error TS2322: Source has 3 element(s) but target allows only 2.
var tf: [string, (x: string) => number] = ["hello", x => x.length];
declare function ff<T, U>(a: T, b: [T, (x: T) => U]): U;
var ff1 = ff("hello", ["foo", x => x.length]);
var ff1: number;
function tuple2<T0, T1>(item0: T0, item1: T1): [T0, T1]{
return [item0, item1];
}
var tt = tuple2(1, "string");
var tt0 = tt[0];
var tt0: number;
var tt1 = tt[1];
var tt1: string;
var tt2 = tt[2];
~
!!! error TS2493: Tuple type '[number, string]' of length '2' has no element at index '2'.
var tt2: number | string;
~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'tt2' must be of type 'undefined', but here has type 'string | number'.
!!! related TS6203 tests/cases/compiler/tupleTypes.ts:35:5: 'tt2' was also declared here.
tt = tuple2(1, undefined);
tt = [1, undefined];
tt = [undefined, undefined];
tt = []; // Error
~~
!!! error TS2322: Type '[]' is not assignable to type '[number, string]'.
var a: number[];
var a1: [number, string];
var a2: [number, number];
var a3: [number, {}];
a = a1; // Error
~
!!! error TS2322: Type '[number, string]' is not assignable to type 'number[]'.
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
a = a2;
a = a3; // Error
~
!!! error TS2322: Type '[number, {}]' is not assignable to type 'number[]'.
!!! error TS2322: Type 'number | {}' is not assignable to type 'number'.
!!! error TS2322: Type '{}' is not assignable to type 'number'.
a1 = a2; // Error
~~
!!! error TS2322: Type '[number, number]' is not assignable to type '[number, string]'.
!!! error TS2322: Type at position 1 in source is not compatible with type at position 1 in target.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
a1 = a3; // Error
~~
!!! error TS2322: Type '[number, {}]' is not assignable to type '[number, string]'.
!!! error TS2322: Type at position 1 in source is not compatible with type at position 1 in target.
!!! error TS2322: Type '{}' is not assignable to type 'string'.
a3 = a1;
a3 = a2;
type B = Pick<[number], 'length'>;
declare const b: B;
b.length = 0; // Error
~~~~~~~~
!!! error TS2322: Type '0' is not assignable to type '1'.
declare const b1: readonly [number?];
b1.length = 0; // Error
~~~~~~
!!! error TS2540: Cannot assign to 'length' because it is a read-only property.
declare const b2: readonly [number, ...number[]];
b2.length = 0; // Error
~~~~~~
!!! error TS2540: Cannot assign to 'length' because it is a read-only property.
declare const b3: readonly number[];
b3.length = 0; // Error
~~~~~~
!!! error TS2540: Cannot assign to 'length' because it is a read-only property.
declare const b4: [number?];
b4.length = 0;
|