File: abstractClassUnionInstantiation.js

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (51 lines) | stat: -rw-r--r-- 1,709 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
//// [abstractClassUnionInstantiation.ts]
class ConcreteA {}
class ConcreteB {}
abstract class AbstractA { a: string; }
abstract class AbstractB { b: string; }

type Abstracts = typeof AbstractA | typeof AbstractB;
type Concretes = typeof ConcreteA | typeof ConcreteB;
type ConcretesOrAbstracts = Concretes | Abstracts;

declare const cls1: ConcretesOrAbstracts;
declare const cls2: Abstracts;
declare const cls3: Concretes;

new cls1(); // should error
new cls2(); // should error
new cls3(); // should work

[ConcreteA, AbstractA, AbstractB].map(cls => new cls()); // should error
[AbstractA, AbstractB, ConcreteA].map(cls => new cls()); // should error
[ConcreteA, ConcreteB].map(cls => new cls()); // should work
[AbstractA, AbstractB].map(cls => new cls()); // should error

//// [abstractClassUnionInstantiation.js]
var ConcreteA = /** @class */ (function () {
    function ConcreteA() {
    }
    return ConcreteA;
}());
var ConcreteB = /** @class */ (function () {
    function ConcreteB() {
    }
    return ConcreteB;
}());
var AbstractA = /** @class */ (function () {
    function AbstractA() {
    }
    return AbstractA;
}());
var AbstractB = /** @class */ (function () {
    function AbstractB() {
    }
    return AbstractB;
}());
new cls1(); // should error
new cls2(); // should error
new cls3(); // should work
[ConcreteA, AbstractA, AbstractB].map(function (cls) { return new cls(); }); // should error
[AbstractA, AbstractB, ConcreteA].map(function (cls) { return new cls(); }); // should error
[ConcreteA, ConcreteB].map(function (cls) { return new cls(); }); // should work
[AbstractA, AbstractB].map(function (cls) { return new cls(); }); // should error