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
|
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(11,29): error TS1257: A required element cannot follow an optional element.
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(15,5): error TS2322: Type 'T2' is not assignable to type 'T1'.
Source provides no match for required element at position 2 in target.
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(16,5): error TS2322: Type 'T3' is not assignable to type 'T1'.
Source provides no match for required element at position 1 in target.
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(17,5): error TS2322: Type 'T4' is not assignable to type 'T1'.
Source provides no match for required element at position 0 in target.
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(20,5): error TS2322: Type 'T3' is not assignable to type 'T2'.
Source provides no match for required element at position 1 in target.
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(21,5): error TS2322: Type 'T4' is not assignable to type 'T2'.
Source provides no match for required element at position 0 in target.
tests/cases/conformance/types/tuple/optionalTupleElements1.ts(25,5): error TS2322: Type 'T4' is not assignable to type 'T3'.
Source provides no match for required element at position 0 in target.
==== tests/cases/conformance/types/tuple/optionalTupleElements1.ts (7 errors) ====
type T1 = [number, string, boolean];
type T2 = [number, string, boolean?];
type T3 = [number, string?, boolean?];
type T4 = [number?, string?, boolean?];
type L1 = T1["length"];
type L2 = T2["length"];
type L3 = T3["length"];
type L4 = T4["length"];
type T5 = [number, string?, boolean]; // Error
~~~~~~~
!!! error TS1257: A required element cannot follow an optional element.
function f1(t1: T1, t2: T2, t3: T3, t4: T4) {
t1 = t1;
t1 = t2; // Error
~~
!!! error TS2322: Type 'T2' is not assignable to type 'T1'.
!!! error TS2322: Source provides no match for required element at position 2 in target.
t1 = t3; // Error
~~
!!! error TS2322: Type 'T3' is not assignable to type 'T1'.
!!! error TS2322: Source provides no match for required element at position 1 in target.
t1 = t4; // Error
~~
!!! error TS2322: Type 'T4' is not assignable to type 'T1'.
!!! error TS2322: Source provides no match for required element at position 0 in target.
t2 = t1;
t2 = t2;
t2 = t3; // Error
~~
!!! error TS2322: Type 'T3' is not assignable to type 'T2'.
!!! error TS2322: Source provides no match for required element at position 1 in target.
t2 = t4; // Error
~~
!!! error TS2322: Type 'T4' is not assignable to type 'T2'.
!!! error TS2322: Source provides no match for required element at position 0 in target.
t3 = t1;
t3 = t2;
t3 = t3;
t3 = t4; // Error
~~
!!! error TS2322: Type 'T4' is not assignable to type 'T3'.
!!! error TS2322: Source provides no match for required element at position 0 in target.
t4 = t1;
t4 = t2;
t4 = t3;
t4 = t4;
}
let t2: T2;
let t3: T3;
let t4: T4;
t2 = [42, "hello"];
t3 = [42, "hello"];
t3 = [42,,true]
t3 = [42];
t4 = [42, "hello"];
t4 = [42,,true];
t4 = [,"hello", true];
t4 = [,,true];
t4 = [];
|