File: abstractClassUnionInstantiation.types

package info (click to toggle)
node-typescript 5.0.4%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 459,116 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (99 lines) | stat: -rw-r--r-- 4,567 bytes parent folder | download | duplicates (3)
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
=== tests/cases/compiler/abstractClassUnionInstantiation.ts ===
class ConcreteA {}
>ConcreteA : ConcreteA

class ConcreteB {}
>ConcreteB : ConcreteB

abstract class AbstractA { a: string; }
>AbstractA : AbstractA
>a : string

abstract class AbstractB { b: string; }
>AbstractB : AbstractB
>b : string

type Abstracts = typeof AbstractA | typeof AbstractB;
>Abstracts : typeof AbstractA | typeof AbstractB
>AbstractA : typeof AbstractA
>AbstractB : typeof AbstractB

type Concretes = typeof ConcreteA | typeof ConcreteB;
>Concretes : typeof ConcreteA | typeof ConcreteB
>ConcreteA : typeof ConcreteA
>ConcreteB : typeof ConcreteB

type ConcretesOrAbstracts = Concretes | Abstracts;
>ConcretesOrAbstracts : Abstracts | Concretes

declare const cls1: ConcretesOrAbstracts;
>cls1 : ConcretesOrAbstracts

declare const cls2: Abstracts;
>cls2 : Abstracts

declare const cls3: Concretes;
>cls3 : Concretes

new cls1(); // should error
>new cls1() : any
>cls1 : ConcretesOrAbstracts

new cls2(); // should error
>new cls2() : any
>cls2 : Abstracts

new cls3(); // should work
>new cls3() : ConcreteA | ConcreteB
>cls3 : Concretes

[ConcreteA, AbstractA, AbstractB].map(cls => new cls()); // should error
>[ConcreteA, AbstractA, AbstractB].map(cls => new cls()) : any[]
>[ConcreteA, AbstractA, AbstractB].map : <U>(callbackfn: (value: typeof ConcreteA | typeof AbstractA | typeof AbstractB, index: number, array: (typeof ConcreteA | typeof AbstractA | typeof AbstractB)[]) => U, thisArg?: any) => U[]
>[ConcreteA, AbstractA, AbstractB] : (typeof ConcreteA | typeof AbstractA | typeof AbstractB)[]
>ConcreteA : typeof ConcreteA
>AbstractA : typeof AbstractA
>AbstractB : typeof AbstractB
>map : <U>(callbackfn: (value: typeof ConcreteA | typeof AbstractA | typeof AbstractB, index: number, array: (typeof ConcreteA | typeof AbstractA | typeof AbstractB)[]) => U, thisArg?: any) => U[]
>cls => new cls() : (cls: typeof ConcreteA | typeof AbstractA | typeof AbstractB) => any
>cls : typeof ConcreteA | typeof AbstractA | typeof AbstractB
>new cls() : any
>cls : typeof ConcreteA | typeof AbstractA | typeof AbstractB

[AbstractA, AbstractB, ConcreteA].map(cls => new cls()); // should error
>[AbstractA, AbstractB, ConcreteA].map(cls => new cls()) : any[]
>[AbstractA, AbstractB, ConcreteA].map : <U>(callbackfn: (value: typeof ConcreteA | typeof AbstractA | typeof AbstractB, index: number, array: (typeof ConcreteA | typeof AbstractA | typeof AbstractB)[]) => U, thisArg?: any) => U[]
>[AbstractA, AbstractB, ConcreteA] : (typeof ConcreteA | typeof AbstractA | typeof AbstractB)[]
>AbstractA : typeof AbstractA
>AbstractB : typeof AbstractB
>ConcreteA : typeof ConcreteA
>map : <U>(callbackfn: (value: typeof ConcreteA | typeof AbstractA | typeof AbstractB, index: number, array: (typeof ConcreteA | typeof AbstractA | typeof AbstractB)[]) => U, thisArg?: any) => U[]
>cls => new cls() : (cls: typeof ConcreteA | typeof AbstractA | typeof AbstractB) => any
>cls : typeof ConcreteA | typeof AbstractA | typeof AbstractB
>new cls() : any
>cls : typeof ConcreteA | typeof AbstractA | typeof AbstractB

[ConcreteA, ConcreteB].map(cls => new cls()); // should work
>[ConcreteA, ConcreteB].map(cls => new cls()) : ConcreteA[]
>[ConcreteA, ConcreteB].map : <U>(callbackfn: (value: typeof ConcreteA, index: number, array: (typeof ConcreteA)[]) => U, thisArg?: any) => U[]
>[ConcreteA, ConcreteB] : (typeof ConcreteA)[]
>ConcreteA : typeof ConcreteA
>ConcreteB : typeof ConcreteB
>map : <U>(callbackfn: (value: typeof ConcreteA, index: number, array: (typeof ConcreteA)[]) => U, thisArg?: any) => U[]
>cls => new cls() : (cls: typeof ConcreteA) => ConcreteA
>cls : typeof ConcreteA
>new cls() : ConcreteA
>cls : typeof ConcreteA

[AbstractA, AbstractB].map(cls => new cls()); // should error
>[AbstractA, AbstractB].map(cls => new cls()) : any[]
>[AbstractA, AbstractB].map : <U>(callbackfn: (value: typeof AbstractA | typeof AbstractB, index: number, array: (typeof AbstractA | typeof AbstractB)[]) => U, thisArg?: any) => U[]
>[AbstractA, AbstractB] : (typeof AbstractA | typeof AbstractB)[]
>AbstractA : typeof AbstractA
>AbstractB : typeof AbstractB
>map : <U>(callbackfn: (value: typeof AbstractA | typeof AbstractB, index: number, array: (typeof AbstractA | typeof AbstractB)[]) => U, thisArg?: any) => U[]
>cls => new cls() : (cls: typeof AbstractA | typeof AbstractB) => any
>cls : typeof AbstractA | typeof AbstractB
>new cls() : any
>cls : typeof AbstractA | typeof AbstractB