mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
45 lines
2.5 KiB
Plaintext
45 lines
2.5 KiB
Plaintext
abstractClassUnionInstantiation.ts(3,28): error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor.
|
|
abstractClassUnionInstantiation.ts(4,28): error TS2564: Property 'b' has no initializer and is not definitely assigned in the constructor.
|
|
abstractClassUnionInstantiation.ts(14,1): error TS2511: Cannot create an instance of an abstract class.
|
|
abstractClassUnionInstantiation.ts(15,1): error TS2511: Cannot create an instance of an abstract class.
|
|
abstractClassUnionInstantiation.ts(18,46): error TS2511: Cannot create an instance of an abstract class.
|
|
abstractClassUnionInstantiation.ts(19,46): error TS2511: Cannot create an instance of an abstract class.
|
|
abstractClassUnionInstantiation.ts(21,35): error TS2511: Cannot create an instance of an abstract class.
|
|
|
|
|
|
==== abstractClassUnionInstantiation.ts (7 errors) ====
|
|
class ConcreteA {}
|
|
class ConcreteB {}
|
|
abstract class AbstractA { a: string; }
|
|
~
|
|
!!! error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor.
|
|
abstract class AbstractB { b: string; }
|
|
~
|
|
!!! error TS2564: Property 'b' has no initializer and is not definitely assigned in the constructor.
|
|
|
|
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
|
|
~~~~~~~~~~
|
|
!!! error TS2511: Cannot create an instance of an abstract class.
|
|
new cls2(); // should error
|
|
~~~~~~~~~~
|
|
!!! error TS2511: Cannot create an instance of an abstract class.
|
|
new cls3(); // should work
|
|
|
|
[ConcreteA, AbstractA, AbstractB].map(cls => new cls()); // should error
|
|
~~~~~~~~~
|
|
!!! error TS2511: Cannot create an instance of an abstract class.
|
|
[AbstractA, AbstractB, ConcreteA].map(cls => new cls()); // should error
|
|
~~~~~~~~~
|
|
!!! error TS2511: Cannot create an instance of an abstract class.
|
|
[ConcreteA, ConcreteB].map(cls => new cls()); // should work
|
|
[AbstractA, AbstractB].map(cls => new cls()); // should error
|
|
~~~~~~~~~
|
|
!!! error TS2511: Cannot create an instance of an abstract class. |