Test error w/exported class extending intersection
This commit is contained in:
parent
cd272e8244
commit
2f27e85a18
6 changed files with 213 additions and 59 deletions
|
@ -1,11 +1,13 @@
|
||||||
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(2,10): error TS4060: Return type of exported function has or is using private name 'D'.
|
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(2,10): error TS4060: Return type of exported function has or is using private name 'D'.
|
||||||
|
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(6,7): error TS4093: Extends clause of exported class 'C' refers to a type with no declaration.
|
||||||
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(6,17): error TS2315: Type 'D' is not generic.
|
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(6,17): error TS2315: Type 'D' is not generic.
|
||||||
|
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(10,7): error TS4093: Extends clause of exported class 'C2' refers to a type with no declaration.
|
||||||
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(10,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
|
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(10,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
|
||||||
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(15,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
|
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(15,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
|
||||||
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(15,18): error TS4020: Extends clause of exported class 'C3' has or is using private name 'SomeUndefinedFunction'.
|
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(15,18): error TS4020: Extends clause of exported class 'C3' has or is using private name 'SomeUndefinedFunction'.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/compiler/declarationEmitExpressionInExtends4.ts (5 errors) ====
|
==== tests/cases/compiler/declarationEmitExpressionInExtends4.ts (7 errors) ====
|
||||||
|
|
||||||
function getSomething() {
|
function getSomething() {
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
@ -14,12 +16,16 @@ tests/cases/compiler/declarationEmitExpressionInExtends4.ts(15,18): error TS4020
|
||||||
}
|
}
|
||||||
|
|
||||||
class C extends getSomething()<number, string> {
|
class C extends getSomething()<number, string> {
|
||||||
|
~
|
||||||
|
!!! error TS4093: Extends clause of exported class 'C' refers to a type with no declaration.
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
!!! error TS2315: Type 'D' is not generic.
|
!!! error TS2315: Type 'D' is not generic.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class C2 extends SomeUndefinedFunction()<number, string> {
|
class C2 extends SomeUndefinedFunction()<number, string> {
|
||||||
|
~~
|
||||||
|
!!! error TS4093: Extends clause of exported class 'C2' refers to a type with no declaration.
|
||||||
~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~
|
||||||
!!! error TS2304: Cannot find name 'SomeUndefinedFunction'.
|
!!! error TS2304: Cannot find name 'SomeUndefinedFunction'.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
tests/cases/compiler/FinalClass.ts(4,14): error TS4093: Extends clause of exported class 'MyExtendedClass' refers to a type with no declaration.
|
||||||
|
|
||||||
|
|
||||||
|
==== tests/cases/compiler/BaseClass.ts (0 errors) ====
|
||||||
|
export type Constructor<T> = new (...args: any[]) => T;
|
||||||
|
|
||||||
|
export class MyBaseClass<T> {
|
||||||
|
baseProperty: string;
|
||||||
|
constructor(value: T) {}
|
||||||
|
}
|
||||||
|
==== tests/cases/compiler/MixinClass.ts (0 errors) ====
|
||||||
|
import { Constructor, MyBaseClass } from './BaseClass';
|
||||||
|
|
||||||
|
export interface MyMixin {
|
||||||
|
mixinProperty: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MyMixin<T extends Constructor<MyBaseClass<any>>>(base: T): T & Constructor<MyMixin> {
|
||||||
|
return class extends base {
|
||||||
|
mixinProperty: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
==== tests/cases/compiler/FinalClass.ts (1 errors) ====
|
||||||
|
import { MyBaseClass } from './BaseClass';
|
||||||
|
import { MyMixin } from './MixinClass';
|
||||||
|
|
||||||
|
export class MyExtendedClass extends MyMixin(MyBaseClass)<string> {
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
!!! error TS4093: Extends clause of exported class 'MyExtendedClass' refers to a type with no declaration.
|
||||||
|
extendedClassProperty: number;
|
||||||
|
}
|
||||||
|
==== tests/cases/compiler/Main.ts (0 errors) ====
|
||||||
|
import { MyExtendedClass } from './FinalClass';
|
||||||
|
import { MyMixin } from './MixinClass';
|
||||||
|
|
||||||
|
const myExtendedClass = new MyExtendedClass('string');
|
||||||
|
|
||||||
|
const AnotherMixedClass = MyMixin(MyExtendedClass);
|
||||||
|
|
114
tests/baselines/reference/exportClassExtendingIntersection.js
Normal file
114
tests/baselines/reference/exportClassExtendingIntersection.js
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
//// [tests/cases/compiler/exportClassExtendingIntersection.ts] ////
|
||||||
|
|
||||||
|
//// [BaseClass.ts]
|
||||||
|
export type Constructor<T> = new (...args: any[]) => T;
|
||||||
|
|
||||||
|
export class MyBaseClass<T> {
|
||||||
|
baseProperty: string;
|
||||||
|
constructor(value: T) {}
|
||||||
|
}
|
||||||
|
//// [MixinClass.ts]
|
||||||
|
import { Constructor, MyBaseClass } from './BaseClass';
|
||||||
|
|
||||||
|
export interface MyMixin {
|
||||||
|
mixinProperty: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MyMixin<T extends Constructor<MyBaseClass<any>>>(base: T): T & Constructor<MyMixin> {
|
||||||
|
return class extends base {
|
||||||
|
mixinProperty: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//// [FinalClass.ts]
|
||||||
|
import { MyBaseClass } from './BaseClass';
|
||||||
|
import { MyMixin } from './MixinClass';
|
||||||
|
|
||||||
|
export class MyExtendedClass extends MyMixin(MyBaseClass)<string> {
|
||||||
|
extendedClassProperty: number;
|
||||||
|
}
|
||||||
|
//// [Main.ts]
|
||||||
|
import { MyExtendedClass } from './FinalClass';
|
||||||
|
import { MyMixin } from './MixinClass';
|
||||||
|
|
||||||
|
const myExtendedClass = new MyExtendedClass('string');
|
||||||
|
|
||||||
|
const AnotherMixedClass = MyMixin(MyExtendedClass);
|
||||||
|
|
||||||
|
|
||||||
|
//// [BaseClass.js]
|
||||||
|
"use strict";
|
||||||
|
exports.__esModule = true;
|
||||||
|
var MyBaseClass = (function () {
|
||||||
|
function MyBaseClass(value) {
|
||||||
|
}
|
||||||
|
return MyBaseClass;
|
||||||
|
}());
|
||||||
|
exports.MyBaseClass = MyBaseClass;
|
||||||
|
//// [MixinClass.js]
|
||||||
|
"use strict";
|
||||||
|
var __extends = (this && this.__extends) || (function () {
|
||||||
|
var extendStatics = Object.setPrototypeOf ||
|
||||||
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||||
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||||
|
return function (d, b) {
|
||||||
|
extendStatics(d, b);
|
||||||
|
function __() { this.constructor = d; }
|
||||||
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
exports.__esModule = true;
|
||||||
|
function MyMixin(base) {
|
||||||
|
return (function (_super) {
|
||||||
|
__extends(class_1, _super);
|
||||||
|
function class_1() {
|
||||||
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
}
|
||||||
|
return class_1;
|
||||||
|
}(base));
|
||||||
|
}
|
||||||
|
exports.MyMixin = MyMixin;
|
||||||
|
//// [FinalClass.js]
|
||||||
|
"use strict";
|
||||||
|
var __extends = (this && this.__extends) || (function () {
|
||||||
|
var extendStatics = Object.setPrototypeOf ||
|
||||||
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||||
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||||
|
return function (d, b) {
|
||||||
|
extendStatics(d, b);
|
||||||
|
function __() { this.constructor = d; }
|
||||||
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
exports.__esModule = true;
|
||||||
|
var BaseClass_1 = require("./BaseClass");
|
||||||
|
var MixinClass_1 = require("./MixinClass");
|
||||||
|
var MyExtendedClass = (function (_super) {
|
||||||
|
__extends(MyExtendedClass, _super);
|
||||||
|
function MyExtendedClass() {
|
||||||
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
}
|
||||||
|
return MyExtendedClass;
|
||||||
|
}(MixinClass_1.MyMixin(BaseClass_1.MyBaseClass)));
|
||||||
|
exports.MyExtendedClass = MyExtendedClass;
|
||||||
|
//// [Main.js]
|
||||||
|
"use strict";
|
||||||
|
exports.__esModule = true;
|
||||||
|
var FinalClass_1 = require("./FinalClass");
|
||||||
|
var MixinClass_1 = require("./MixinClass");
|
||||||
|
var myExtendedClass = new FinalClass_1.MyExtendedClass('string');
|
||||||
|
var AnotherMixedClass = MixinClass_1.MyMixin(FinalClass_1.MyExtendedClass);
|
||||||
|
|
||||||
|
|
||||||
|
//// [BaseClass.d.ts]
|
||||||
|
export declare type Constructor<T> = new (...args: any[]) => T;
|
||||||
|
export declare class MyBaseClass<T> {
|
||||||
|
baseProperty: string;
|
||||||
|
constructor(value: T);
|
||||||
|
}
|
||||||
|
//// [MixinClass.d.ts]
|
||||||
|
import { Constructor, MyBaseClass } from './BaseClass';
|
||||||
|
export interface MyMixin {
|
||||||
|
mixinProperty: string;
|
||||||
|
}
|
||||||
|
export declare function MyMixin<T extends Constructor<MyBaseClass<any>>>(base: T): T & Constructor<MyMixin>;
|
||||||
|
//// [Main.d.ts]
|
|
@ -5,19 +5,25 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(51,4): error TS2445: Pro
|
||||||
tests/cases/conformance/classes/mixinAccessModifiers.ts(66,7): error TS2415: Class 'C1' incorrectly extends base class 'Private & Private2'.
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(66,7): error TS2415: Class 'C1' incorrectly extends base class 'Private & Private2'.
|
||||||
Type 'C1' is not assignable to type 'Private'.
|
Type 'C1' is not assignable to type 'Private'.
|
||||||
Property 'p' has conflicting declarations and is inaccessible in type 'C1'.
|
Property 'p' has conflicting declarations and is inaccessible in type 'C1'.
|
||||||
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(66,7): error TS4093: Extends clause of exported class 'C1' refers to a type with no declaration.
|
||||||
tests/cases/conformance/classes/mixinAccessModifiers.ts(67,7): error TS2415: Class 'C2' incorrectly extends base class 'Private & Protected'.
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(67,7): error TS2415: Class 'C2' incorrectly extends base class 'Private & Protected'.
|
||||||
Type 'C2' is not assignable to type 'Private'.
|
Type 'C2' is not assignable to type 'Private'.
|
||||||
Property 'p' has conflicting declarations and is inaccessible in type 'C2'.
|
Property 'p' has conflicting declarations and is inaccessible in type 'C2'.
|
||||||
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(67,7): error TS4093: Extends clause of exported class 'C2' refers to a type with no declaration.
|
||||||
tests/cases/conformance/classes/mixinAccessModifiers.ts(68,7): error TS2415: Class 'C3' incorrectly extends base class 'Private & Public'.
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(68,7): error TS2415: Class 'C3' incorrectly extends base class 'Private & Public'.
|
||||||
Type 'C3' is not assignable to type 'Private'.
|
Type 'C3' is not assignable to type 'Private'.
|
||||||
Property 'p' has conflicting declarations and is inaccessible in type 'C3'.
|
Property 'p' has conflicting declarations and is inaccessible in type 'C3'.
|
||||||
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(68,7): error TS4093: Extends clause of exported class 'C3' refers to a type with no declaration.
|
||||||
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(70,7): error TS4093: Extends clause of exported class 'C4' refers to a type with no declaration.
|
||||||
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(83,7): error TS4093: Extends clause of exported class 'C5' refers to a type with no declaration.
|
||||||
tests/cases/conformance/classes/mixinAccessModifiers.ts(85,6): error TS2445: Property 'p' is protected and only accessible within class 'C4' and its subclasses.
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(85,6): error TS2445: Property 'p' is protected and only accessible within class 'C4' and its subclasses.
|
||||||
tests/cases/conformance/classes/mixinAccessModifiers.ts(90,6): error TS2445: Property 's' is protected and only accessible within class 'typeof C4' and its subclasses.
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(90,6): error TS2445: Property 's' is protected and only accessible within class 'typeof C4' and its subclasses.
|
||||||
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(96,7): error TS4093: Extends clause of exported class 'C6' refers to a type with no declaration.
|
||||||
tests/cases/conformance/classes/mixinAccessModifiers.ts(98,6): error TS2445: Property 'p' is protected and only accessible within class 'C4' and its subclasses.
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(98,6): error TS2445: Property 'p' is protected and only accessible within class 'C4' and its subclasses.
|
||||||
tests/cases/conformance/classes/mixinAccessModifiers.ts(103,6): error TS2445: Property 's' is protected and only accessible within class 'typeof C4' and its subclasses.
|
tests/cases/conformance/classes/mixinAccessModifiers.ts(103,6): error TS2445: Property 's' is protected and only accessible within class 'typeof C4' and its subclasses.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/classes/mixinAccessModifiers.ts (11 errors) ====
|
==== tests/cases/conformance/classes/mixinAccessModifiers.ts (17 errors) ====
|
||||||
|
|
||||||
type Constructable = new (...args: any[]) => object;
|
type Constructable = new (...args: any[]) => object;
|
||||||
|
|
||||||
|
@ -96,18 +102,26 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(103,6): error TS2445: Pr
|
||||||
!!! error TS2415: Class 'C1' incorrectly extends base class 'Private & Private2'.
|
!!! error TS2415: Class 'C1' incorrectly extends base class 'Private & Private2'.
|
||||||
!!! error TS2415: Type 'C1' is not assignable to type 'Private'.
|
!!! error TS2415: Type 'C1' is not assignable to type 'Private'.
|
||||||
!!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C1'.
|
!!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C1'.
|
||||||
|
~~
|
||||||
|
!!! error TS4093: Extends clause of exported class 'C1' refers to a type with no declaration.
|
||||||
class C2 extends Mix(Private, Protected) {}
|
class C2 extends Mix(Private, Protected) {}
|
||||||
~~
|
~~
|
||||||
!!! error TS2415: Class 'C2' incorrectly extends base class 'Private & Protected'.
|
!!! error TS2415: Class 'C2' incorrectly extends base class 'Private & Protected'.
|
||||||
!!! error TS2415: Type 'C2' is not assignable to type 'Private'.
|
!!! error TS2415: Type 'C2' is not assignable to type 'Private'.
|
||||||
!!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C2'.
|
!!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C2'.
|
||||||
|
~~
|
||||||
|
!!! error TS4093: Extends clause of exported class 'C2' refers to a type with no declaration.
|
||||||
class C3 extends Mix(Private, Public) {}
|
class C3 extends Mix(Private, Public) {}
|
||||||
~~
|
~~
|
||||||
!!! error TS2415: Class 'C3' incorrectly extends base class 'Private & Public'.
|
!!! error TS2415: Class 'C3' incorrectly extends base class 'Private & Public'.
|
||||||
!!! error TS2415: Type 'C3' is not assignable to type 'Private'.
|
!!! error TS2415: Type 'C3' is not assignable to type 'Private'.
|
||||||
!!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C3'.
|
!!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C3'.
|
||||||
|
~~
|
||||||
|
!!! error TS4093: Extends clause of exported class 'C3' refers to a type with no declaration.
|
||||||
|
|
||||||
class C4 extends Mix(Protected, Protected2) {
|
class C4 extends Mix(Protected, Protected2) {
|
||||||
|
~~
|
||||||
|
!!! error TS4093: Extends clause of exported class 'C4' refers to a type with no declaration.
|
||||||
f(c4: C4, c5: C5, c6: C6) {
|
f(c4: C4, c5: C5, c6: C6) {
|
||||||
c4.p;
|
c4.p;
|
||||||
c5.p;
|
c5.p;
|
||||||
|
@ -121,6 +135,8 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(103,6): error TS2445: Pr
|
||||||
}
|
}
|
||||||
|
|
||||||
class C5 extends Mix(Protected, Public) {
|
class C5 extends Mix(Protected, Public) {
|
||||||
|
~~
|
||||||
|
!!! error TS4093: Extends clause of exported class 'C5' refers to a type with no declaration.
|
||||||
f(c4: C4, c5: C5, c6: C6) {
|
f(c4: C4, c5: C5, c6: C6) {
|
||||||
c4.p; // Error, not in class deriving from Protected2
|
c4.p; // Error, not in class deriving from Protected2
|
||||||
~
|
~
|
||||||
|
@ -138,6 +154,8 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(103,6): error TS2445: Pr
|
||||||
}
|
}
|
||||||
|
|
||||||
class C6 extends Mix(Public, Public2) {
|
class C6 extends Mix(Public, Public2) {
|
||||||
|
~~
|
||||||
|
!!! error TS4093: Extends clause of exported class 'C6' refers to a type with no declaration.
|
||||||
f(c4: C4, c5: C5, c6: C6) {
|
f(c4: C4, c5: C5, c6: C6) {
|
||||||
c4.p; // Error, not in class deriving from Protected2
|
c4.p; // Error, not in class deriving from Protected2
|
||||||
~
|
~
|
||||||
|
|
|
@ -264,60 +264,3 @@ var C6 = (function (_super) {
|
||||||
};
|
};
|
||||||
return C6;
|
return C6;
|
||||||
}(Mix(Public, Public2)));
|
}(Mix(Public, Public2)));
|
||||||
|
|
||||||
|
|
||||||
//// [mixinAccessModifiers.d.ts]
|
|
||||||
declare type Constructable = new (...args: any[]) => object;
|
|
||||||
declare class Private {
|
|
||||||
constructor(...args: any[]);
|
|
||||||
private p;
|
|
||||||
}
|
|
||||||
declare class Private2 {
|
|
||||||
constructor(...args: any[]);
|
|
||||||
private p;
|
|
||||||
}
|
|
||||||
declare class Protected {
|
|
||||||
constructor(...args: any[]);
|
|
||||||
protected p: string;
|
|
||||||
protected static s: string;
|
|
||||||
}
|
|
||||||
declare class Protected2 {
|
|
||||||
constructor(...args: any[]);
|
|
||||||
protected p: string;
|
|
||||||
protected static s: string;
|
|
||||||
}
|
|
||||||
declare class Public {
|
|
||||||
constructor(...args: any[]);
|
|
||||||
p: string;
|
|
||||||
static s: string;
|
|
||||||
}
|
|
||||||
declare class Public2 {
|
|
||||||
constructor(...args: any[]);
|
|
||||||
p: string;
|
|
||||||
static s: string;
|
|
||||||
}
|
|
||||||
declare function f1(x: Private & Private2): void;
|
|
||||||
declare function f2(x: Private & Protected): void;
|
|
||||||
declare function f3(x: Private & Public): void;
|
|
||||||
declare function f4(x: Protected & Protected2): void;
|
|
||||||
declare function f5(x: Protected & Public): void;
|
|
||||||
declare function f6(x: Public & Public2): void;
|
|
||||||
declare function Mix<T, U>(c1: T, c2: U): T & U;
|
|
||||||
declare class C1 extends Private & Private2 {
|
|
||||||
}
|
|
||||||
declare class C2 extends Private & Protected {
|
|
||||||
}
|
|
||||||
declare class C3 extends Private & Public {
|
|
||||||
}
|
|
||||||
declare class C4 extends Protected & Protected2 {
|
|
||||||
f(c4: C4, c5: C5, c6: C6): void;
|
|
||||||
static g(): void;
|
|
||||||
}
|
|
||||||
declare class C5 extends Protected & Public {
|
|
||||||
f(c4: C4, c5: C5, c6: C6): void;
|
|
||||||
static g(): void;
|
|
||||||
}
|
|
||||||
declare class C6 extends Public & Public2 {
|
|
||||||
f(c4: C4, c5: C5, c6: C6): void;
|
|
||||||
static g(): void;
|
|
||||||
}
|
|
||||||
|
|
34
tests/cases/compiler/exportClassExtendingIntersection.ts
Normal file
34
tests/cases/compiler/exportClassExtendingIntersection.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// @declaration: true
|
||||||
|
// @Filename:BaseClass.ts
|
||||||
|
export type Constructor<T> = new (...args: any[]) => T;
|
||||||
|
|
||||||
|
export class MyBaseClass<T> {
|
||||||
|
baseProperty: string;
|
||||||
|
constructor(value: T) {}
|
||||||
|
}
|
||||||
|
// @Filename:MixinClass.ts
|
||||||
|
import { Constructor, MyBaseClass } from './BaseClass';
|
||||||
|
|
||||||
|
export interface MyMixin {
|
||||||
|
mixinProperty: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MyMixin<T extends Constructor<MyBaseClass<any>>>(base: T): T & Constructor<MyMixin> {
|
||||||
|
return class extends base {
|
||||||
|
mixinProperty: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// @Filename:FinalClass.ts
|
||||||
|
import { MyBaseClass } from './BaseClass';
|
||||||
|
import { MyMixin } from './MixinClass';
|
||||||
|
|
||||||
|
export class MyExtendedClass extends MyMixin(MyBaseClass)<string> {
|
||||||
|
extendedClassProperty: number;
|
||||||
|
}
|
||||||
|
// @Filename:Main.ts
|
||||||
|
import { MyExtendedClass } from './FinalClass';
|
||||||
|
import { MyMixin } from './MixinClass';
|
||||||
|
|
||||||
|
const myExtendedClass = new MyExtendedClass('string');
|
||||||
|
|
||||||
|
const AnotherMixedClass = MyMixin(MyExtendedClass);
|
Loading…
Reference in a new issue