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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
//// [genericRestParameters3.ts]
declare let f1: (x: string, ...args: [string] | [number, boolean]) => void;
declare let f2: (x: string, y: string) => void;
declare let f3: (x: string, y: number, z: boolean) => void;
declare let f4: (...args: [string, string] | [string, number, boolean]) => void;
declare const t1: [string] | [number, boolean];
declare const t2: readonly [string] | [number, boolean];
declare const t3: [string] | readonly [number, boolean];
declare const t4: readonly [string] | readonly [number, boolean];
f1("foo", "abc");
f1("foo", 10, true);
f1("foo", ...t1);
f1("foo", ...t2);
f1("foo", ...t3);
f1("foo", ...t4);
f1("foo", 10); // Error
f1("foo"); // Error
f2 = f1;
f3 = f1;
f4 = f1;
f1 = f2; // Error
f1 = f3; // Error
f1 = f4;
// Repro from #26110
interface CoolArray<E> extends Array<E> {
hello: number;
}
declare function foo<T extends any[]>(cb: (...args: T) => void): void;
foo<CoolArray<any>>(); // Error
foo<CoolArray<any>>(100); // Error
foo<CoolArray<any>>(foo); // Error
function bar<T extends any[]>(...args: T): T {
return args;
}
let a = bar(10, 20);
let b = bar<CoolArray<number>>(10, 20); // Error
declare function baz<T>(...args: CoolArray<T>): void;
declare const ca: CoolArray<number>;
baz(); // Error
baz(1); // Error
baz(1, 2); // Error
baz(...ca); // Error
// Repro from #26491
declare function hmm<A extends [] | [number, string]>(...args: A): void;
hmm(); // okay, A = []
hmm(1, "s"); // okay, A = [1, "s"]
hmm("what"); // no error? A = [] | [number, string] ?
// Repro from #35066
declare function foo2(...args: string[] | number[]): void;
let x2: ReadonlyArray<string> = ["hello"];
foo2(...x2);
// Repros from #47754
type RestParams = [y: string] | [y: number];
type Signature = (x: string, ...rest: RestParams) => void;
type MergedParams = Parameters<Signature>; // [x: string, y: string] | [x: string, y: number]
declare let ff1: (...rest: [string, string] | [string, number]) => void;
declare let ff2: (x: string, ...rest: [string] | [number]) => void;
ff1 = ff2;
ff2 = ff1;
function ff3<A extends unknown[]>(s1: (...args: [x: string, ...rest: A | [number]]) => void, s2: (x: string, ...rest: A | [number]) => void) {
s1 = s2;
s2 = s1;
}
//// [genericRestParameters3.js]
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
f1("foo", "abc");
f1("foo", 10, true);
f1.apply(void 0, __spreadArray(["foo"], t1, false));
f1.apply(void 0, __spreadArray(["foo"], t2, false));
f1.apply(void 0, __spreadArray(["foo"], t3, false));
f1.apply(void 0, __spreadArray(["foo"], t4, false));
f1("foo", 10); // Error
f1("foo"); // Error
f2 = f1;
f3 = f1;
f4 = f1;
f1 = f2; // Error
f1 = f3; // Error
f1 = f4;
foo(); // Error
foo(100); // Error
foo(foo); // Error
function bar() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return args;
}
var a = bar(10, 20);
var b = bar(10, 20); // Error
baz(); // Error
baz(1); // Error
baz(1, 2); // Error
baz.apply(void 0, ca); // Error
hmm(); // okay, A = []
hmm(1, "s"); // okay, A = [1, "s"]
hmm("what"); // no error? A = [] | [number, string] ?
var x2 = ["hello"];
foo2.apply(void 0, x2);
ff1 = ff2;
ff2 = ff1;
function ff3(s1, s2) {
s1 = s2;
s2 = s1;
}
//// [genericRestParameters3.d.ts]
declare let f1: (x: string, ...args: [string] | [number, boolean]) => void;
declare let f2: (x: string, y: string) => void;
declare let f3: (x: string, y: number, z: boolean) => void;
declare let f4: (...args: [string, string] | [string, number, boolean]) => void;
declare const t1: [string] | [number, boolean];
declare const t2: readonly [string] | [number, boolean];
declare const t3: [string] | readonly [number, boolean];
declare const t4: readonly [string] | readonly [number, boolean];
interface CoolArray<E> extends Array<E> {
hello: number;
}
declare function foo<T extends any[]>(cb: (...args: T) => void): void;
declare function bar<T extends any[]>(...args: T): T;
declare let a: [number, number];
declare let b: CoolArray<number>;
declare function baz<T>(...args: CoolArray<T>): void;
declare const ca: CoolArray<number>;
declare function hmm<A extends [] | [number, string]>(...args: A): void;
declare function foo2(...args: string[] | number[]): void;
declare let x2: ReadonlyArray<string>;
type RestParams = [y: string] | [y: number];
type Signature = (x: string, ...rest: RestParams) => void;
type MergedParams = Parameters<Signature>;
declare let ff1: (...rest: [string, string] | [string, number]) => void;
declare let ff2: (x: string, ...rest: [string] | [number]) => void;
declare function ff3<A extends unknown[]>(s1: (...args: [x: string, ...rest: A | [number]]) => void, s2: (x: string, ...rest: A | [number]) => void): void;
|