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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
=== tests/cases/conformance/types/rest/genericRestParameters3.ts ===
declare let f1: (x: string, ...args: [string] | [number, boolean]) => void;
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>x : string
>args : [string] | [number, boolean]
declare let f2: (x: string, y: string) => void;
>f2 : (x: string, y: string) => void
>x : string
>y : string
declare let f3: (x: string, y: number, z: boolean) => void;
>f3 : (x: string, y: number, z: boolean) => void
>x : string
>y : number
>z : boolean
declare let f4: (...args: [string, string] | [string, number, boolean]) => void;
>f4 : (...args: [string, string] | [string, number, boolean]) => void
>args : [string, string] | [string, number, boolean]
declare const t1: [string] | [number, boolean];
>t1 : [string] | [number, boolean]
declare const t2: readonly [string] | [number, boolean];
>t2 : [number, boolean] | readonly [string]
declare const t3: [string] | readonly [number, boolean];
>t3 : [string] | readonly [number, boolean]
declare const t4: readonly [string] | readonly [number, boolean];
>t4 : readonly [string] | readonly [number, boolean]
f1("foo", "abc");
>f1("foo", "abc") : void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>"foo" : "foo"
>"abc" : "abc"
f1("foo", 10, true);
>f1("foo", 10, true) : void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>"foo" : "foo"
>10 : 10
>true : true
f1("foo", ...t1);
>f1("foo", ...t1) : void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>"foo" : "foo"
>...t1 : string | number | boolean
>t1 : [string] | [number, boolean]
f1("foo", ...t2);
>f1("foo", ...t2) : void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>"foo" : "foo"
>...t2 : string | number | boolean
>t2 : [number, boolean] | readonly [string]
f1("foo", ...t3);
>f1("foo", ...t3) : void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>"foo" : "foo"
>...t3 : string | number | boolean
>t3 : [string] | readonly [number, boolean]
f1("foo", ...t4);
>f1("foo", ...t4) : void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>"foo" : "foo"
>...t4 : string | number | boolean
>t4 : readonly [string] | readonly [number, boolean]
f1("foo", 10); // Error
>f1("foo", 10) : void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>"foo" : "foo"
>10 : 10
f1("foo"); // Error
>f1("foo") : void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>"foo" : "foo"
f2 = f1;
>f2 = f1 : (x: string, ...args: [string] | [number, boolean]) => void
>f2 : (x: string, y: string) => void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
f3 = f1;
>f3 = f1 : (x: string, ...args: [string] | [number, boolean]) => void
>f3 : (x: string, y: number, z: boolean) => void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
f4 = f1; // Error, misaligned complex rest types
>f4 = f1 : (x: string, ...args: [string] | [number, boolean]) => void
>f4 : (...args: [string, string] | [string, number, boolean]) => void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
f1 = f2; // Error
>f1 = f2 : (x: string, y: string) => void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>f2 : (x: string, y: string) => void
f1 = f3; // Error
>f1 = f3 : (x: string, y: number, z: boolean) => void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>f3 : (x: string, y: number, z: boolean) => void
f1 = f4; // Error, misaligned complex rest types
>f1 = f4 : (...args: [string, string] | [string, number, boolean]) => void
>f1 : (x: string, ...args: [string] | [number, boolean]) => void
>f4 : (...args: [string, string] | [string, number, boolean]) => void
// Repro from #26110
interface CoolArray<E> extends Array<E> {
hello: number;
>hello : number
}
declare function foo<T extends any[]>(cb: (...args: T) => void): void;
>foo : <T extends any[]>(cb: (...args: T) => void) => void
>cb : (...args: T) => void
>args : T
foo<CoolArray<any>>(); // Error
>foo<CoolArray<any>>() : void
>foo : <T extends any[]>(cb: (...args: T) => void) => void
foo<CoolArray<any>>(100); // Error
>foo<CoolArray<any>>(100) : void
>foo : <T extends any[]>(cb: (...args: T) => void) => void
>100 : 100
foo<CoolArray<any>>(foo); // Error
>foo<CoolArray<any>>(foo) : void
>foo : <T extends any[]>(cb: (...args: T) => void) => void
>foo : <T extends any[]>(cb: (...args: T) => void) => void
function bar<T extends any[]>(...args: T): T {
>bar : <T extends any[]>(...args: T) => T
>args : T
return args;
>args : T
}
let a = bar(10, 20);
>a : [number, number]
>bar(10, 20) : [number, number]
>bar : <T extends any[]>(...args: T) => T
>10 : 10
>20 : 20
let b = bar<CoolArray<number>>(10, 20); // Error
>b : CoolArray<number>
>bar<CoolArray<number>>(10, 20) : CoolArray<number>
>bar : <T extends any[]>(...args: T) => T
>10 : 10
>20 : 20
declare function baz<T>(...args: CoolArray<T>): void;
>baz : <T>(...args: CoolArray<T>) => void
>args : CoolArray<T>
declare const ca: CoolArray<number>;
>ca : CoolArray<number>
baz(); // Error
>baz() : void
>baz : <T>(...args: CoolArray<T>) => void
baz(1); // Error
>baz(1) : void
>baz : <T>(...args: CoolArray<T>) => void
>1 : 1
baz(1, 2); // Error
>baz(1, 2) : void
>baz : <T>(...args: CoolArray<T>) => void
>1 : 1
>2 : 2
baz(...ca); // Error
>baz(...ca) : void
>baz : <T>(...args: CoolArray<T>) => void
>...ca : number
>ca : CoolArray<number>
// Repro from #26491
declare function hmm<A extends [] | [number, string]>(...args: A): void;
>hmm : <A extends [] | [number, string]>(...args: A) => void
>args : A
hmm(); // okay, A = []
>hmm() : void
>hmm : <A extends [] | [number, string]>(...args: A) => void
hmm(1, "s"); // okay, A = [1, "s"]
>hmm(1, "s") : void
>hmm : <A extends [] | [number, string]>(...args: A) => void
>1 : 1
>"s" : "s"
hmm("what"); // no error? A = [] | [number, string] ?
>hmm("what") : void
>hmm : <A extends [] | [number, string]>(...args: A) => void
>"what" : "what"
// Repro from #35066
declare function foo2(...args: string[] | number[]): void;
>foo2 : (...args: string[] | number[]) => void
>args : string[] | number[]
let x2: ReadonlyArray<string> = ["hello"];
>x2 : readonly string[]
>["hello"] : string[]
>"hello" : "hello"
foo2(...x2);
>foo2(...x2) : void
>foo2 : (...args: string[] | number[]) => void
>...x2 : string
>x2 : readonly string[]
|