|
| 1 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(11,11): error TS2345: Argument of type '[10]' is not assignable to parameter of type '[string] | [number, boolean]'. |
| 2 | + Type '[10]' is not assignable to type '[string]'. |
| 3 | + Type '10' is not assignable to type 'string'. |
| 4 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(12,1): error TS2345: Argument of type '[]' is not assignable to parameter of type '[string] | [number, boolean]'. |
| 5 | + Type '[]' is not assignable to type '[number, boolean]'. |
| 6 | + Property '0' is missing in type '[]'. |
| 7 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(16,1): error TS2322: Type '(x: string, ...args: [string] | [number, boolean]) => void' is not assignable to type '(...args: [string, string] | [string, number, boolean]) => void'. |
| 8 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(17,1): error TS2322: Type '(x: string, y: string) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'. |
| 9 | + Types of parameters 'y' and 'args' are incompatible. |
| 10 | + Type '[string] | [number, boolean]' is not assignable to type '[string]'. |
| 11 | + Type '[number, boolean]' is not assignable to type '[string]'. |
| 12 | + Types of property '0' are incompatible. |
| 13 | + Type 'number' is not assignable to type 'string'. |
| 14 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(18,1): error TS2322: Type '(x: string, y: number, z: boolean) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'. |
| 15 | + Types of parameters 'y' and 'args' are incompatible. |
| 16 | + Type '[string] | [number, boolean]' is not assignable to type '[number, boolean]'. |
| 17 | + Type '[string]' is not assignable to type '[number, boolean]'. |
| 18 | + Property '1' is missing in type '[string]'. |
| 19 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(19,1): error TS2322: Type '(...args: [string, string] | [string, number, boolean]) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'. |
| 20 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(29,1): error TS2554: Expected 1 arguments, but got 0. |
| 21 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(30,21): error TS2345: Argument of type '100' is not assignable to parameter of type '(...args: CoolArray<any>) => void'. |
| 22 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(31,21): error TS2345: Argument of type '<T extends any[]>(cb: (...args: T) => void) => void' is not assignable to parameter of type '(...args: CoolArray<any>) => void'. |
| 23 | + Types of parameters 'cb' and 'args' are incompatible. |
| 24 | + Type 'CoolArray<any>' is not assignable to type '[(...args: any[]) => void]'. |
| 25 | + Property '0' is missing in type 'CoolArray<any>'. |
| 26 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(38,32): error TS2345: Argument of type '[10, 20]' is not assignable to parameter of type 'CoolArray<number>'. |
| 27 | + Property 'hello' is missing in type '[10, 20]'. |
| 28 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(43,1): error TS2345: Argument of type '[]' is not assignable to parameter of type 'CoolArray<never>'. |
| 29 | + Property 'hello' is missing in type '[]'. |
| 30 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(44,5): error TS2345: Argument of type '[number]' is not assignable to parameter of type 'CoolArray<{}>'. |
| 31 | + Property 'hello' is missing in type '[number]'. |
| 32 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(45,5): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type 'CoolArray<{}>'. |
| 33 | + Property 'hello' is missing in type '[number, number]'. |
| 34 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(46,5): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'CoolArray<number>'. |
| 35 | + Property 'hello' is missing in type 'number[]'. |
| 36 | +tests/cases/conformance/types/rest/genericRestParameters3.ts(53,5): error TS2345: Argument of type '["what"]' is not assignable to parameter of type '[] | [number, string]'. |
| 37 | + Type '["what"]' is not assignable to type '[number, string]'. |
| 38 | + Property '1' is missing in type '["what"]'. |
| 39 | + |
| 40 | + |
| 41 | +==== tests/cases/conformance/types/rest/genericRestParameters3.ts (15 errors) ==== |
| 42 | + declare let f1: (x: string, ...args: [string] | [number, boolean]) => void; |
| 43 | + declare let f2: (x: string, y: string) => void; |
| 44 | + declare let f3: (x: string, y: number, z: boolean) => void; |
| 45 | + declare let f4: (...args: [string, string] | [string, number, boolean]) => void; |
| 46 | + |
| 47 | + declare const tt: [string] | [number, boolean]; |
| 48 | + |
| 49 | + f1("foo", "abc"); |
| 50 | + f1("foo", 10, true); |
| 51 | + f1("foo", ...tt); |
| 52 | + f1("foo", 10); // Error |
| 53 | + ~~ |
| 54 | +!!! error TS2345: Argument of type '[10]' is not assignable to parameter of type '[string] | [number, boolean]'. |
| 55 | +!!! error TS2345: Type '[10]' is not assignable to type '[string]'. |
| 56 | +!!! error TS2345: Type '10' is not assignable to type 'string'. |
| 57 | + f1("foo"); // Error |
| 58 | + ~~~~~~~~~ |
| 59 | +!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[string] | [number, boolean]'. |
| 60 | +!!! error TS2345: Type '[]' is not assignable to type '[number, boolean]'. |
| 61 | +!!! error TS2345: Property '0' is missing in type '[]'. |
| 62 | + |
| 63 | + f2 = f1; |
| 64 | + f3 = f1; |
| 65 | + f4 = f1; // Error, misaligned complex rest types |
| 66 | + ~~ |
| 67 | +!!! error TS2322: Type '(x: string, ...args: [string] | [number, boolean]) => void' is not assignable to type '(...args: [string, string] | [string, number, boolean]) => void'. |
| 68 | + f1 = f2; // Error |
| 69 | + ~~ |
| 70 | +!!! error TS2322: Type '(x: string, y: string) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'. |
| 71 | +!!! error TS2322: Types of parameters 'y' and 'args' are incompatible. |
| 72 | +!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type '[string]'. |
| 73 | +!!! error TS2322: Type '[number, boolean]' is not assignable to type '[string]'. |
| 74 | +!!! error TS2322: Types of property '0' are incompatible. |
| 75 | +!!! error TS2322: Type 'number' is not assignable to type 'string'. |
| 76 | + f1 = f3; // Error |
| 77 | + ~~ |
| 78 | +!!! error TS2322: Type '(x: string, y: number, z: boolean) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'. |
| 79 | +!!! error TS2322: Types of parameters 'y' and 'args' are incompatible. |
| 80 | +!!! error TS2322: Type '[string] | [number, boolean]' is not assignable to type '[number, boolean]'. |
| 81 | +!!! error TS2322: Type '[string]' is not assignable to type '[number, boolean]'. |
| 82 | +!!! error TS2322: Property '1' is missing in type '[string]'. |
| 83 | + f1 = f4; // Error, misaligned complex rest types |
| 84 | + ~~ |
| 85 | +!!! error TS2322: Type '(...args: [string, string] | [string, number, boolean]) => void' is not assignable to type '(x: string, ...args: [string] | [number, boolean]) => void'. |
| 86 | + |
| 87 | + // Repro from #26110 |
| 88 | + |
| 89 | + interface CoolArray<E> extends Array<E> { |
| 90 | + hello: number; |
| 91 | + } |
| 92 | + |
| 93 | + declare function foo<T extends any[]>(cb: (...args: T) => void): void; |
| 94 | + |
| 95 | + foo<CoolArray<any>>(); // Error |
| 96 | + ~~~~~~~~~~~~~~~~~~~~~ |
| 97 | +!!! error TS2554: Expected 1 arguments, but got 0. |
| 98 | + foo<CoolArray<any>>(100); // Error |
| 99 | + ~~~ |
| 100 | +!!! error TS2345: Argument of type '100' is not assignable to parameter of type '(...args: CoolArray<any>) => void'. |
| 101 | + foo<CoolArray<any>>(foo); // Error |
| 102 | + ~~~ |
| 103 | +!!! error TS2345: Argument of type '<T extends any[]>(cb: (...args: T) => void) => void' is not assignable to parameter of type '(...args: CoolArray<any>) => void'. |
| 104 | +!!! error TS2345: Types of parameters 'cb' and 'args' are incompatible. |
| 105 | +!!! error TS2345: Type 'CoolArray<any>' is not assignable to type '[(...args: any[]) => void]'. |
| 106 | +!!! error TS2345: Property '0' is missing in type 'CoolArray<any>'. |
| 107 | + |
| 108 | + function bar<T extends any[]>(...args: T): T { |
| 109 | + return args; |
| 110 | + } |
| 111 | + |
| 112 | + let a = bar(10, 20); |
| 113 | + let b = bar<CoolArray<number>>(10, 20); // Error |
| 114 | + ~~ |
| 115 | +!!! error TS2345: Argument of type '[10, 20]' is not assignable to parameter of type 'CoolArray<number>'. |
| 116 | +!!! error TS2345: Property 'hello' is missing in type '[10, 20]'. |
| 117 | + |
| 118 | + declare function baz<T>(...args: CoolArray<T>): void; |
| 119 | + declare const ca: CoolArray<number>; |
| 120 | + |
| 121 | + baz(); // Error |
| 122 | + ~~~~~ |
| 123 | +!!! error TS2345: Argument of type '[]' is not assignable to parameter of type 'CoolArray<never>'. |
| 124 | +!!! error TS2345: Property 'hello' is missing in type '[]'. |
| 125 | + baz(1); // Error |
| 126 | + ~ |
| 127 | +!!! error TS2345: Argument of type '[number]' is not assignable to parameter of type 'CoolArray<{}>'. |
| 128 | +!!! error TS2345: Property 'hello' is missing in type '[number]'. |
| 129 | + baz(1, 2); // Error |
| 130 | + ~ |
| 131 | +!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type 'CoolArray<{}>'. |
| 132 | +!!! error TS2345: Property 'hello' is missing in type '[number, number]'. |
| 133 | + baz(...ca); // Error |
| 134 | + ~~~~~ |
| 135 | +!!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'CoolArray<number>'. |
| 136 | +!!! error TS2345: Property 'hello' is missing in type 'number[]'. |
| 137 | + |
| 138 | + // Repro from #26491 |
| 139 | + |
| 140 | + declare function hmm<A extends [] | [number, string]>(...args: A): void; |
| 141 | + hmm(); // okay, A = [] |
| 142 | + hmm(1, "s"); // okay, A = [1, "s"] |
| 143 | + hmm("what"); // no error? A = [] | [number, string] ? |
| 144 | + ~~~~~~ |
| 145 | +!!! error TS2345: Argument of type '["what"]' is not assignable to parameter of type '[] | [number, string]'. |
| 146 | +!!! error TS2345: Type '["what"]' is not assignable to type '[number, string]'. |
| 147 | +!!! error TS2345: Property '1' is missing in type '["what"]'. |
| 148 | + |
0 commit comments