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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
|
=== tests/cases/conformance/types/union/unionTypeConstructSignatures.ts ===
var numOrDate: number | Date;
>numOrDate : number | Date
var strOrBoolean: string | boolean;
>strOrBoolean : string | boolean
var strOrNum: string | number;
>strOrNum : string | number
// If each type in U has construct signatures and the sets of construct signatures are identical ignoring return types,
// U has the same set of construct signatures, but with return types that are unions of the return types of the respective construct signatures from each type in U.
var unionOfDifferentReturnType: { new (a: number): number; } | { new (a: number): Date; };
>unionOfDifferentReturnType : (new (a: number) => number) | (new (a: number) => Date)
>a : number
>a : number
numOrDate = new unionOfDifferentReturnType(10);
>numOrDate = new unionOfDifferentReturnType(10) : number | Date
>numOrDate : number | Date
>new unionOfDifferentReturnType(10) : number | Date
>unionOfDifferentReturnType : (new (a: number) => number) | (new (a: number) => Date)
>10 : 10
strOrBoolean = new unionOfDifferentReturnType("hello"); // error
>strOrBoolean = new unionOfDifferentReturnType("hello") : number | Date
>strOrBoolean : string | boolean
>new unionOfDifferentReturnType("hello") : number | Date
>unionOfDifferentReturnType : (new (a: number) => number) | (new (a: number) => Date)
>"hello" : "hello"
new unionOfDifferentReturnType1(true); // error in type of parameter
>new unionOfDifferentReturnType1(true) : (number | Date) & (string | boolean)
>unionOfDifferentReturnType1 : { new (a: number): number; new (a: string): string; } | { new (a: number): Date; new (a: string): boolean; }
>true : true
var unionOfDifferentReturnType1: { new (a: number): number; new (a: string): string; } | { new (a: number): Date; new (a: string): boolean; };
>unionOfDifferentReturnType1 : { new (a: number): number; new (a: string): string; } | { new (a: number): Date; new (a: string): boolean; }
>a : number
>a : string
>a : number
>a : string
numOrDate = new unionOfDifferentReturnType1(10);
>numOrDate = new unionOfDifferentReturnType1(10) : number | Date
>numOrDate : number | Date
>new unionOfDifferentReturnType1(10) : number | Date
>unionOfDifferentReturnType1 : { new (a: number): number; new (a: string): string; } | { new (a: number): Date; new (a: string): boolean; }
>10 : 10
strOrBoolean = new unionOfDifferentReturnType1("hello");
>strOrBoolean = new unionOfDifferentReturnType1("hello") : string | boolean
>strOrBoolean : string | boolean
>new unionOfDifferentReturnType1("hello") : string | boolean
>unionOfDifferentReturnType1 : { new (a: number): number; new (a: string): string; } | { new (a: number): Date; new (a: string): boolean; }
>"hello" : "hello"
new unionOfDifferentReturnType1(true); // error in type of parameter
>new unionOfDifferentReturnType1(true) : (number | Date) & (string | boolean)
>unionOfDifferentReturnType1 : { new (a: number): number; new (a: string): string; } | { new (a: number): Date; new (a: string): boolean; }
>true : true
new unionOfDifferentReturnType1(); // error missing parameter
>new unionOfDifferentReturnType1() : (number | Date) & (string | boolean)
>unionOfDifferentReturnType1 : { new (a: number): number; new (a: string): string; } | { new (a: number): Date; new (a: string): boolean; }
var unionOfDifferentParameterTypes: { new (a: number): number; } | { new (a: string): Date; };
>unionOfDifferentParameterTypes : (new (a: number) => number) | (new (a: string) => Date)
>a : number
>a : string
new unionOfDifferentParameterTypes(10);// error - no call signatures
>new unionOfDifferentParameterTypes(10) : number | Date
>unionOfDifferentParameterTypes : (new (a: number) => number) | (new (a: string) => Date)
>10 : 10
new unionOfDifferentParameterTypes("hello");// error - no call signatures
>new unionOfDifferentParameterTypes("hello") : number | Date
>unionOfDifferentParameterTypes : (new (a: number) => number) | (new (a: string) => Date)
>"hello" : "hello"
new unionOfDifferentParameterTypes();// error - no call signatures
>new unionOfDifferentParameterTypes() : number | Date
>unionOfDifferentParameterTypes : (new (a: number) => number) | (new (a: string) => Date)
var unionOfDifferentNumberOfSignatures: { new (a: number): number; } | { new (a: number): Date; new (a: string): boolean; };
>unionOfDifferentNumberOfSignatures : (new (a: number) => number) | { new (a: number): Date; new (a: string): boolean; }
>a : number
>a : number
>a : string
new unionOfDifferentNumberOfSignatures(); // error - no call signatures
>new unionOfDifferentNumberOfSignatures() : number | Date
>unionOfDifferentNumberOfSignatures : (new (a: number) => number) | { new (a: number): Date; new (a: string): boolean; }
new unionOfDifferentNumberOfSignatures(10); // error - no call signatures
>new unionOfDifferentNumberOfSignatures(10) : number | Date
>unionOfDifferentNumberOfSignatures : (new (a: number) => number) | { new (a: number): Date; new (a: string): boolean; }
>10 : 10
new unionOfDifferentNumberOfSignatures("hello"); // error - no call signatures
>new unionOfDifferentNumberOfSignatures("hello") : number | Date
>unionOfDifferentNumberOfSignatures : (new (a: number) => number) | { new (a: number): Date; new (a: string): boolean; }
>"hello" : "hello"
var unionWithDifferentParameterCount: { new (a: string): string; } | { new (a: string, b: number): number; };
>unionWithDifferentParameterCount : (new (a: string) => string) | (new (a: string, b: number) => number)
>a : string
>a : string
>b : number
new unionWithDifferentParameterCount();// needs more args
>new unionWithDifferentParameterCount() : string | number
>unionWithDifferentParameterCount : (new (a: string) => string) | (new (a: string, b: number) => number)
new unionWithDifferentParameterCount("hello");// needs more args
>new unionWithDifferentParameterCount("hello") : string | number
>unionWithDifferentParameterCount : (new (a: string) => string) | (new (a: string, b: number) => number)
>"hello" : "hello"
new unionWithDifferentParameterCount("hello", 10);// ok
>new unionWithDifferentParameterCount("hello", 10) : string | number
>unionWithDifferentParameterCount : (new (a: string) => string) | (new (a: string, b: number) => number)
>"hello" : "hello"
>10 : 10
var unionWithOptionalParameter1: { new (a: string, b?: number): string; } | { new (a: string, b?: number): number; };
>unionWithOptionalParameter1 : (new (a: string, b?: number) => string) | (new (a: string, b?: number) => number)
>a : string
>b : number
>a : string
>b : number
strOrNum = new unionWithOptionalParameter1('hello');
>strOrNum = new unionWithOptionalParameter1('hello') : string | number
>strOrNum : string | number
>new unionWithOptionalParameter1('hello') : string | number
>unionWithOptionalParameter1 : (new (a: string, b?: number) => string) | (new (a: string, b?: number) => number)
>'hello' : "hello"
strOrNum = new unionWithOptionalParameter1('hello', 10);
>strOrNum = new unionWithOptionalParameter1('hello', 10) : string | number
>strOrNum : string | number
>new unionWithOptionalParameter1('hello', 10) : string | number
>unionWithOptionalParameter1 : (new (a: string, b?: number) => string) | (new (a: string, b?: number) => number)
>'hello' : "hello"
>10 : 10
strOrNum = new unionWithOptionalParameter1('hello', "hello"); // error in parameter type
>strOrNum = new unionWithOptionalParameter1('hello', "hello") : string | number
>strOrNum : string | number
>new unionWithOptionalParameter1('hello', "hello") : string | number
>unionWithOptionalParameter1 : (new (a: string, b?: number) => string) | (new (a: string, b?: number) => number)
>'hello' : "hello"
>"hello" : "hello"
strOrNum = new unionWithOptionalParameter1(); // error
>strOrNum = new unionWithOptionalParameter1() : string | number
>strOrNum : string | number
>new unionWithOptionalParameter1() : string | number
>unionWithOptionalParameter1 : (new (a: string, b?: number) => string) | (new (a: string, b?: number) => number)
var unionWithOptionalParameter2: { new (a: string, b?: number): string; } | { new (a: string, b: number): number };
>unionWithOptionalParameter2 : (new (a: string, b?: number) => string) | (new (a: string, b: number) => number)
>a : string
>b : number
>a : string
>b : number
strOrNum = new unionWithOptionalParameter2('hello'); // error no call signature
>strOrNum = new unionWithOptionalParameter2('hello') : string | number
>strOrNum : string | number
>new unionWithOptionalParameter2('hello') : string | number
>unionWithOptionalParameter2 : (new (a: string, b?: number) => string) | (new (a: string, b: number) => number)
>'hello' : "hello"
strOrNum = new unionWithOptionalParameter2('hello', 10); // error no call signature
>strOrNum = new unionWithOptionalParameter2('hello', 10) : string | number
>strOrNum : string | number
>new unionWithOptionalParameter2('hello', 10) : string | number
>unionWithOptionalParameter2 : (new (a: string, b?: number) => string) | (new (a: string, b: number) => number)
>'hello' : "hello"
>10 : 10
strOrNum = new unionWithOptionalParameter2('hello', "hello"); // error no call signature
>strOrNum = new unionWithOptionalParameter2('hello', "hello") : string | number
>strOrNum : string | number
>new unionWithOptionalParameter2('hello', "hello") : string | number
>unionWithOptionalParameter2 : (new (a: string, b?: number) => string) | (new (a: string, b: number) => number)
>'hello' : "hello"
>"hello" : "hello"
strOrNum = new unionWithOptionalParameter2(); // error no call signature
>strOrNum = new unionWithOptionalParameter2() : string | number
>strOrNum : string | number
>new unionWithOptionalParameter2() : string | number
>unionWithOptionalParameter2 : (new (a: string, b?: number) => string) | (new (a: string, b: number) => number)
var unionWithOptionalParameter3: { new (a: string, b?: number): string; } | { new (a: string): number; };
>unionWithOptionalParameter3 : (new (a: string, b?: number) => string) | (new (a: string) => number)
>a : string
>b : number
>a : string
strOrNum = new unionWithOptionalParameter3('hello'); // error no call signature
>strOrNum = new unionWithOptionalParameter3('hello') : string | number
>strOrNum : string | number
>new unionWithOptionalParameter3('hello') : string | number
>unionWithOptionalParameter3 : (new (a: string, b?: number) => string) | (new (a: string) => number)
>'hello' : "hello"
strOrNum = new unionWithOptionalParameter3('hello', 10); // ok
>strOrNum = new unionWithOptionalParameter3('hello', 10) : string | number
>strOrNum : string | number
>new unionWithOptionalParameter3('hello', 10) : string | number
>unionWithOptionalParameter3 : (new (a: string, b?: number) => string) | (new (a: string) => number)
>'hello' : "hello"
>10 : 10
strOrNum = new unionWithOptionalParameter3('hello', "hello"); // wrong type
>strOrNum = new unionWithOptionalParameter3('hello', "hello") : string | number
>strOrNum : string | number
>new unionWithOptionalParameter3('hello', "hello") : string | number
>unionWithOptionalParameter3 : (new (a: string, b?: number) => string) | (new (a: string) => number)
>'hello' : "hello"
>"hello" : "hello"
strOrNum = new unionWithOptionalParameter3(); // error no call signature
>strOrNum = new unionWithOptionalParameter3() : string | number
>strOrNum : string | number
>new unionWithOptionalParameter3() : string | number
>unionWithOptionalParameter3 : (new (a: string, b?: number) => string) | (new (a: string) => number)
var unionWithRestParameter1: { new (a: string, ...b: number[]): string; } | { new (a: string, ...b: number[]): number };
>unionWithRestParameter1 : (new (a: string, ...b: number[]) => string) | (new (a: string, ...b: number[]) => number)
>a : string
>b : number[]
>a : string
>b : number[]
strOrNum = new unionWithRestParameter1('hello');
>strOrNum = new unionWithRestParameter1('hello') : string | number
>strOrNum : string | number
>new unionWithRestParameter1('hello') : string | number
>unionWithRestParameter1 : (new (a: string, ...b: number[]) => string) | (new (a: string, ...b: number[]) => number)
>'hello' : "hello"
strOrNum = new unionWithRestParameter1('hello', 10);
>strOrNum = new unionWithRestParameter1('hello', 10) : string | number
>strOrNum : string | number
>new unionWithRestParameter1('hello', 10) : string | number
>unionWithRestParameter1 : (new (a: string, ...b: number[]) => string) | (new (a: string, ...b: number[]) => number)
>'hello' : "hello"
>10 : 10
strOrNum = new unionWithRestParameter1('hello', 10, 11);
>strOrNum = new unionWithRestParameter1('hello', 10, 11) : string | number
>strOrNum : string | number
>new unionWithRestParameter1('hello', 10, 11) : string | number
>unionWithRestParameter1 : (new (a: string, ...b: number[]) => string) | (new (a: string, ...b: number[]) => number)
>'hello' : "hello"
>10 : 10
>11 : 11
strOrNum = new unionWithRestParameter1('hello', "hello"); // error in parameter type
>strOrNum = new unionWithRestParameter1('hello', "hello") : string | number
>strOrNum : string | number
>new unionWithRestParameter1('hello', "hello") : string | number
>unionWithRestParameter1 : (new (a: string, ...b: number[]) => string) | (new (a: string, ...b: number[]) => number)
>'hello' : "hello"
>"hello" : "hello"
strOrNum = new unionWithRestParameter1(); // error
>strOrNum = new unionWithRestParameter1() : string | number
>strOrNum : string | number
>new unionWithRestParameter1() : string | number
>unionWithRestParameter1 : (new (a: string, ...b: number[]) => string) | (new (a: string, ...b: number[]) => number)
var unionWithRestParameter2: { new (a: string, ...b: number[]): string; } | { new (a: string, b: number): number };
>unionWithRestParameter2 : (new (a: string, ...b: number[]) => string) | (new (a: string, b: number) => number)
>a : string
>b : number[]
>a : string
>b : number
strOrNum = new unionWithRestParameter2('hello'); // error no call signature
>strOrNum = new unionWithRestParameter2('hello') : string | number
>strOrNum : string | number
>new unionWithRestParameter2('hello') : string | number
>unionWithRestParameter2 : (new (a: string, ...b: number[]) => string) | (new (a: string, b: number) => number)
>'hello' : "hello"
strOrNum = new unionWithRestParameter2('hello', 10); // error no call signature
>strOrNum = new unionWithRestParameter2('hello', 10) : string | number
>strOrNum : string | number
>new unionWithRestParameter2('hello', 10) : string | number
>unionWithRestParameter2 : (new (a: string, ...b: number[]) => string) | (new (a: string, b: number) => number)
>'hello' : "hello"
>10 : 10
strOrNum = new unionWithRestParameter2('hello', 10, 11); // error no call signature
>strOrNum = new unionWithRestParameter2('hello', 10, 11) : string | number
>strOrNum : string | number
>new unionWithRestParameter2('hello', 10, 11) : string | number
>unionWithRestParameter2 : (new (a: string, ...b: number[]) => string) | (new (a: string, b: number) => number)
>'hello' : "hello"
>10 : 10
>11 : 11
strOrNum = new unionWithRestParameter2('hello', "hello"); // error no call signature
>strOrNum = new unionWithRestParameter2('hello', "hello") : string | number
>strOrNum : string | number
>new unionWithRestParameter2('hello', "hello") : string | number
>unionWithRestParameter2 : (new (a: string, ...b: number[]) => string) | (new (a: string, b: number) => number)
>'hello' : "hello"
>"hello" : "hello"
strOrNum = new unionWithRestParameter2(); // error no call signature
>strOrNum = new unionWithRestParameter2() : string | number
>strOrNum : string | number
>new unionWithRestParameter2() : string | number
>unionWithRestParameter2 : (new (a: string, ...b: number[]) => string) | (new (a: string, b: number) => number)
var unionWithRestParameter3: { new (a: string, ...b: number[]): string; } | { new (a: string): number };
>unionWithRestParameter3 : (new (a: string, ...b: number[]) => string) | (new (a: string) => number)
>a : string
>b : number[]
>a : string
strOrNum = new unionWithRestParameter3('hello'); // error no call signature
>strOrNum = new unionWithRestParameter3('hello') : string | number
>strOrNum : string | number
>new unionWithRestParameter3('hello') : string | number
>unionWithRestParameter3 : (new (a: string, ...b: number[]) => string) | (new (a: string) => number)
>'hello' : "hello"
strOrNum = new unionWithRestParameter3('hello', 10); // ok
>strOrNum = new unionWithRestParameter3('hello', 10) : string | number
>strOrNum : string | number
>new unionWithRestParameter3('hello', 10) : string | number
>unionWithRestParameter3 : (new (a: string, ...b: number[]) => string) | (new (a: string) => number)
>'hello' : "hello"
>10 : 10
strOrNum = new unionWithRestParameter3('hello', 10, 11); // ok
>strOrNum = new unionWithRestParameter3('hello', 10, 11) : string | number
>strOrNum : string | number
>new unionWithRestParameter3('hello', 10, 11) : string | number
>unionWithRestParameter3 : (new (a: string, ...b: number[]) => string) | (new (a: string) => number)
>'hello' : "hello"
>10 : 10
>11 : 11
strOrNum = new unionWithRestParameter3('hello', "hello"); // wrong type
>strOrNum = new unionWithRestParameter3('hello', "hello") : string | number
>strOrNum : string | number
>new unionWithRestParameter3('hello', "hello") : string | number
>unionWithRestParameter3 : (new (a: string, ...b: number[]) => string) | (new (a: string) => number)
>'hello' : "hello"
>"hello" : "hello"
strOrNum = new unionWithRestParameter3(); // error no call signature
>strOrNum = new unionWithRestParameter3() : string | number
>strOrNum : string | number
>new unionWithRestParameter3() : string | number
>unionWithRestParameter3 : (new (a: string, ...b: number[]) => string) | (new (a: string) => number)
var unionWithAbstractSignature: (abstract new (a: string) => string) | (new (a: string) => string);
>unionWithAbstractSignature : (abstract new (a: string) => string) | (new (a: string) => string)
>a : string
>a : string
new unionWithAbstractSignature('hello');
>new unionWithAbstractSignature('hello') : any
>unionWithAbstractSignature : (abstract new (a: string) => string) | (new (a: string) => string)
>'hello' : "hello"
|