|
| 1 | +tests/cases/conformance/types/rest/genericRestParameters1.ts(22,1): error TS2556: Expected 3 arguments, but got 1 or more. |
| 2 | +tests/cases/conformance/types/rest/genericRestParameters1.ts(31,1): error TS2556: Expected 3 arguments, but got 1 or more. |
| 3 | + |
| 4 | + |
| 5 | +==== tests/cases/conformance/types/rest/genericRestParameters1.ts (2 errors) ==== |
| 6 | + declare let f1: (...x: [number, string, boolean]) => void; |
| 7 | + declare let f2: (x0: number, x1: string, x2: boolean) => void; |
| 8 | + |
| 9 | + f1 = f2; |
| 10 | + f2 = f1; |
| 11 | + |
| 12 | + declare const t3: [number, string, boolean]; |
| 13 | + declare const t2: [string, boolean]; |
| 14 | + declare const t1: [boolean]; |
| 15 | + declare const t0: []; |
| 16 | + |
| 17 | + declare const ns: [number, string]; |
| 18 | + declare const sn: [string, number]; |
| 19 | + |
| 20 | + f1(42, "hello", true); |
| 21 | + f1(t3[0], t3[1], t3[2]); |
| 22 | + f1(...t3); |
| 23 | + f1(42, ...t2); |
| 24 | + f1(42, "hello", ...t1); |
| 25 | + f1(42, "hello", true, ...t0); |
| 26 | + f1(ns[0], ns[1], true); |
| 27 | + f1(...ns, true); // Error, tuple spread only expanded when last |
| 28 | + ~~~~~~~~~~~~~~~ |
| 29 | +!!! error TS2556: Expected 3 arguments, but got 1 or more. |
| 30 | + |
| 31 | + f2(42, "hello", true); |
| 32 | + f2(t3[0], t3[1], t3[2]); |
| 33 | + f2(...t3); |
| 34 | + f2(42, ...t2); |
| 35 | + f2(42, "hello", ...t1); |
| 36 | + f2(42, "hello", true, ...t0); |
| 37 | + f2(ns[0], ns[1], true); |
| 38 | + f2(...ns, true); // Error, tuple spread only expanded when last |
| 39 | + ~~~~~~~~~~~~~~~ |
| 40 | +!!! error TS2556: Expected 3 arguments, but got 1 or more. |
| 41 | + |
| 42 | + declare function f10<T extends unknown[]>(...args: T): T; |
| 43 | + |
| 44 | + const x10 = f10(42, "hello", true); // [number, string, boolean] |
| 45 | + const x11 = f10(42, "hello"); // [number, string] |
| 46 | + const x12 = f10(42); // [number] |
| 47 | + const x13 = f10(); // [] |
| 48 | + const x14 = f10(...t3); // [number, string, boolean] |
| 49 | + const x15 = f10(42, ...t2); // [number, string, boolean] |
| 50 | + const x16 = f10(42, "hello", ...t1); // [number, string, boolean] |
| 51 | + const x17 = f10(42, "hello", true, ...t0); // [number, string, boolean] |
| 52 | + const x18 = f10(...ns, true); // (string | number | boolean)[] |
| 53 | + |
| 54 | + function g10<U extends string[], V extends [number, number]>(u: U, v: V) { |
| 55 | + let x1 = f10(...u); // U |
| 56 | + let x2 = f10(...v); // V |
| 57 | + let x3 = f10(1, ...u); // (string | number)[] |
| 58 | + let x4 = f10(...u, ...v); // (string | number)[] |
| 59 | + } |
| 60 | + |
| 61 | + declare function f11<T extends (string | number | boolean)[]>(...args: T): T; |
| 62 | + |
| 63 | + const z10 = f11(42, "hello", true); // [42, "hello", true] |
| 64 | + const z11 = f11(42, "hello"); // [42, "hello"] |
| 65 | + const z12 = f11(42); // [42] |
| 66 | + const z13 = f11(); // [] |
| 67 | + const z14 = f11(...t3); // [number, string, boolean] |
| 68 | + const z15 = f11(42, ...t2); // [42, string, boolean] |
| 69 | + const z16 = f11(42, "hello", ...t1); // [42, "hello", boolean] |
| 70 | + const z17 = f11(42, "hello", true, ...t0); // [42, "hello", true] |
| 71 | + const z18 = f11(...ns, true); // (string | number | true)[] |
| 72 | + |
| 73 | + function g11<U extends string[], V extends [number, number]>(u: U, v: V) { |
| 74 | + let x1 = f11(...u); // U |
| 75 | + let x2 = f11(...v); // V |
| 76 | + let x3 = f11(1, ...u); // (string | 1)[] |
| 77 | + let x4 = f11(...u, ...v); // (string | number)[] |
| 78 | + } |
| 79 | + |
| 80 | + function call<T extends unknown[], U>(f: (...args: T) => U, ...args: T) { |
| 81 | + return f(...args); |
| 82 | + } |
| 83 | + |
| 84 | + function callr<T extends unknown[], U>(args: T, f: (...args: T) => U) { |
| 85 | + return f(...args); |
| 86 | + } |
| 87 | + |
| 88 | + declare function f15(a: string, b: number): string | number; |
| 89 | + declare function f16<A, B>(a: A, b: B): A | B; |
| 90 | + |
| 91 | + let x20 = call((x, y) => x + y, 10, 20); // number |
| 92 | + let x21 = call((x, y) => x + y, 10, "hello"); // string |
| 93 | + let x22 = call(f15, "hello", 42); // string | number |
| 94 | + let x23 = call(f16, "hello", 42); // unknown |
| 95 | + let x24 = call<[string, number], string | number>(f16, "hello", 42); // string | number |
| 96 | + |
| 97 | + let x30 = callr(sn, (x, y) => x + y); // string |
| 98 | + let x31 = callr(sn, f15); // string | number |
| 99 | + let x32 = callr(sn, f16); // string | number |
| 100 | + |
| 101 | + function bind<T, U extends unknown[], V>(f: (x: T, ...rest: U) => V, x: T) { |
| 102 | + return (...rest: U) => f(x, ...rest); |
| 103 | + } |
| 104 | + |
| 105 | + declare const f20: (x: number, y: string, z: boolean) => string[]; |
| 106 | + |
| 107 | + const f21 = bind(f20, 42); // (y: string, z: boolean) => string[] |
| 108 | + const f22 = bind(f21, "hello"); // (z: boolean) => string[] |
| 109 | + const f23 = bind(f22, true); // () => string[] |
| 110 | + |
| 111 | + f20(42, "hello", true); |
| 112 | + f21("hello", true); |
| 113 | + f22(true); |
| 114 | + f23(); |
| 115 | + |
| 116 | + declare const g20: (x: number, y?: string, z?: boolean) => string[]; |
| 117 | + |
| 118 | + const g21 = bind(g20, 42); // (y: string, z: boolean) => string[] |
| 119 | + const g22 = bind(g21, "hello"); // (z: boolean) => string[] |
| 120 | + const g23 = bind(g22, true); // () => string[] |
| 121 | + |
| 122 | + g20(42, "hello", true); |
| 123 | + g20(42, "hello"); |
| 124 | + g20(42); |
| 125 | + g21("hello", true); |
| 126 | + g21("hello"); |
| 127 | + g21(); |
| 128 | + g22(true); |
| 129 | + g22(); |
| 130 | + g23(); |
| 131 | + |
| 132 | + declare function f30<T, U extends ((x: T) => any)[]>(x: T, ...args: U): U; |
| 133 | + |
| 134 | + const c30 = f30(42, x => "" + x, x => x + 1); // [(x: number) => string, (x: number) => number] |
| 135 | + |
| 136 | + type Parameters<T extends Function> = T extends ((...args: infer U) => any) | (new(...args: infer U) => any) ? U : any[]; |
| 137 | + |
| 138 | + type T01 = Parameters<(x: number, y: string, z: boolean) => void>; |
| 139 | + type T02 = Parameters<(...args: [number, string, boolean]) => void>; |
| 140 | + type T03 = Parameters<new (x: number, y: string, z: boolean) => void>; |
| 141 | + type T04 = Parameters<new (...args: [number, string, boolean]) => void>; |
| 142 | + type T05<T> = Parameters<(...args: T[]) => void>; |
| 143 | + type T06<T> = Parameters<new (...args: []) => void>; |
| 144 | + type T07<T extends any[]> = Parameters<(...args: T) => void>; |
| 145 | + type T08<T extends any[]> = Parameters<new (...args: T) => void>; |
| 146 | + type T09 = Parameters<Function>; |
| 147 | + |
| 148 | + type Record1 = { |
| 149 | + move: [number, 'left' | 'right']; |
| 150 | + jump: [number, 'up' | 'down']; |
| 151 | + stop: string; |
| 152 | + done: []; |
| 153 | + } |
| 154 | + |
| 155 | + type EventType<T> = { |
| 156 | + emit<K extends keyof T = keyof T>(e: K, ...payload: T[K] extends any[] ? T[K] : [T[K]]): void; |
| 157 | + } |
| 158 | + |
| 159 | + declare var events: EventType<Record1>; |
| 160 | + events.emit('move', 10, 'left'); |
| 161 | + events.emit('jump', 20, 'up'); |
| 162 | + events.emit('stop', 'Bye!'); |
| 163 | + events.emit('done'); |
| 164 | + |
0 commit comments