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
|
tests/cases/conformance/types/tuple/restTupleElements1.ts(3,22): error TS1257: A required element cannot follow an optional element.
tests/cases/conformance/types/tuple/restTupleElements1.ts(9,13): error TS2574: A rest element type must be an array type.
tests/cases/conformance/types/tuple/restTupleElements1.ts(10,13): error TS2574: A rest element type must be an array type.
tests/cases/conformance/types/tuple/restTupleElements1.ts(10,16): error TS8020: JSDoc types can only be used inside documentation comments.
tests/cases/conformance/types/tuple/restTupleElements1.ts(23,31): error TS2344: Type 'number[]' does not satisfy the constraint '[number, ...number[]]'.
Source provides no match for required element at position 0 in target.
tests/cases/conformance/types/tuple/restTupleElements1.ts(24,31): error TS2344: Type '[]' does not satisfy the constraint '[number, ...number[]]'.
Source has 0 element(s) but target requires 1.
tests/cases/conformance/types/tuple/restTupleElements1.ts(29,18): error TS2344: Type 'number[]' does not satisfy the constraint '[number]'.
Target requires 1 element(s) but source may have fewer.
tests/cases/conformance/types/tuple/restTupleElements1.ts(30,18): error TS2344: Type '[number, ...number[]]' does not satisfy the constraint '[number]'.
Target allows only 1 element(s) but source may have more.
tests/cases/conformance/types/tuple/restTupleElements1.ts(32,31): error TS2344: Type '[number, ...string[]]' does not satisfy the constraint '[number, ...number[]]'.
Type at position 1 in source is not compatible with type at position 1 in target.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/restTupleElements1.ts(33,31): error TS2344: Type '[string, ...number[]]' does not satisfy the constraint '[number, ...number[]]'.
Type at position 0 in source is not compatible with type at position 0 in target.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/restTupleElements1.ts(34,31): error TS2344: Type '[number, number, string]' does not satisfy the constraint '[number, ...number[]]'.
Type at positions 1 through 2 in source is not compatible with type at position 1 in target.
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/restTupleElements1.ts(35,31): error TS2344: Type '[number, number, number, string]' does not satisfy the constraint '[number, ...number[]]'.
Type at positions 1 through 3 in source is not compatible with type at position 1 in target.
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/restTupleElements1.ts(59,4): error TS2345: Argument of type '[]' is not assignable to parameter of type '[unknown, ...unknown[]]'.
Source has 0 element(s) but target requires 1.
==== tests/cases/conformance/types/tuple/restTupleElements1.ts (13 errors) ====
type T00 = [string?];
type T01 = [string, string?];
type T02 = [string?, string]; // Error
~~~~~~
!!! error TS1257: A required element cannot follow an optional element.
type T03 = [...string[]];
type T04 = [...[...string[]]];
type T05 = [...[...[...string[]]]];
type T06 = [string, ...string[]];
type T07 = [...string[], string]; // Error
type T08 = [...string]; // Error
~~~~~~~~~
!!! error TS2574: A rest element type must be an array type.
type T09 = [...string?]; // Error
~~~~~~~~~~
!!! error TS2574: A rest element type must be an array type.
~~~~~~~
!!! error TS8020: JSDoc types can only be used inside documentation comments.
type T10 = [string, ...[...string[]]];
type T11 = [string, ...[...[...string[]]]];
type T15 = [boolean, number, ...string[]];
type L15 = T15["length"]; // number
declare function assign<T, S extends T>(): void;
assign<number[], [...number[]]>();
assign<number[], [number, ...number[]]>();
assign<[...number[]], number[]>();
assign<[number, ...number[]], number[]>(); // Error
~~~~~~~~
!!! error TS2344: Type 'number[]' does not satisfy the constraint '[number, ...number[]]'.
!!! error TS2344: Source provides no match for required element at position 0 in target.
assign<[number, ...number[]], []>(); // Error
~~
!!! error TS2344: Type '[]' does not satisfy the constraint '[number, ...number[]]'.
!!! error TS2344: Source has 0 element(s) but target requires 1.
assign<[number, ...number[]], [number]>();
assign<[number, ...number[]], [number, number]>();
assign<[number, ...number[]], [number, number, ...number[]]>();
assign<[number], [...number[]]>(); // Error
~~~~~~~~~~~~~
!!! error TS2344: Type 'number[]' does not satisfy the constraint '[number]'.
!!! error TS2344: Target requires 1 element(s) but source may have fewer.
assign<[number], [number, ...number[]]>(); // Error
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type '[number, ...number[]]' does not satisfy the constraint '[number]'.
!!! error TS2344: Target allows only 1 element(s) but source may have more.
assign<[number, ...number[]], [number, ...string[]]>(); // Error
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type '[number, ...string[]]' does not satisfy the constraint '[number, ...number[]]'.
!!! error TS2344: Type at position 1 in source is not compatible with type at position 1 in target.
!!! error TS2344: Type 'string' is not assignable to type 'number'.
assign<[number, ...number[]], [string, ...number[]]>(); // Error
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type '[string, ...number[]]' does not satisfy the constraint '[number, ...number[]]'.
!!! error TS2344: Type at position 0 in source is not compatible with type at position 0 in target.
!!! error TS2344: Type 'string' is not assignable to type 'number'.
assign<[number, ...number[]], [number, number, string]>(); // Error
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type '[number, number, string]' does not satisfy the constraint '[number, ...number[]]'.
!!! error TS2344: Type at positions 1 through 2 in source is not compatible with type at position 1 in target.
!!! error TS2344: Type 'string | number' is not assignable to type 'number'.
!!! error TS2344: Type 'string' is not assignable to type 'number'.
assign<[number, ...number[]], [number, number, number, string]>(); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2344: Type '[number, number, number, string]' does not satisfy the constraint '[number, ...number[]]'.
!!! error TS2344: Type at positions 1 through 3 in source is not compatible with type at position 1 in target.
!!! error TS2344: Type 'string | number' is not assignable to type 'number'.
!!! error TS2344: Type 'string' is not assignable to type 'number'.
type T20 = [number, string, ...boolean[]];
type T21 = T20[0];
type T22 = T20[0 | 1];
type T23 = T20[0 | 1 | 2];
type T24 = T20[0 | 1 | 2 | 3];
type T25 = T20[1 | 2 | 3];
type T26 = T20[2 | 3];
type T27 = T20[3];
type T28 = T20[number];
declare const t: T20;
declare const x: number;
let e0 = t[0]; // number
let e1 = t[1]; // string
let e2 = t[2]; // boolean
let e3 = t[3]; // boolean
let ex = t[x]; // number | string | boolean
declare function f0<T, U>(x: [T, ...U[]]): [T, U];
f0([]); // Error
~~
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[unknown, ...unknown[]]'.
!!! error TS2345: Source has 0 element(s) but target requires 1.
f0([1]);
f0([1, 2, 3]);
f0([1, "hello", true]);
declare function f1(a: [(x: number) => number, ...((x: string) => number)[]]): void;
declare function f2(...a: [(x: number) => number, ...((x: string) => number)[]]): void;
f1([x => x * 2, x => x.length, x => x.charCodeAt(0)]);
f2(x => x * 2, x => x.length, x => x.charCodeAt(0));
|