TypeScript/tests/baselines/reference/restTupleElements1.errors.txt
Anders Hejlsberg 5540364c12
Correct tuple relations in --strictOptionalProperties mode (#44568)
* Fix relations for optional elements in tuples with --strictOptionalProperties

* Accept new baselines

* Add regression test

* Address CR feedback
2021-06-13 12:53:13 -07:00

141 lines
8.3 KiB
Plaintext

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));