Skip to content

Commit 454b8ec

Browse files
committed
mixin generics fix
OMG what a nightmare A time sink microsoft/TypeScript#32080
1 parent 6a47743 commit 454b8ec

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/mixins/collection.mixin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { fabric } from '../../HEADER';
22
import { FabricObject } from '../shapes/fabricObject.class';
3-
4-
type Constructor<T = object> = new (...args: any[]) => T;
3+
import { Constructor } from '../typedefs';
54

65
export function createCollectionMixin<TBase extends Constructor>(Base: TBase) {
76
class Collection extends Base {
@@ -155,6 +154,7 @@ export function createCollectionMixin<TBase extends Constructor>(Base: TBase) {
155154
}
156155
}
157156

157+
// https://github.com/microsoft/TypeScript/issues/32080
158158
return Collection as typeof Collection & TBase;
159159
}
160160

src/typedefs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ type TNonFunctionPropertyNames<T> = {
1515
}[keyof T];
1616
export type TClassProperties<T> = Pick<T, TNonFunctionPropertyNames<T>>;
1717

18+
// https://github.com/microsoft/TypeScript/issues/32080
19+
export type Constructor<T = object> = new (...args: any[]) => T;
20+
1821
const enum Degree {}
1922
const enum Radian {}
2023

src/util/applyMixins.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
type TClass = { new (...args: any[]): any };
1+
import { Constructor } from '../typedefs';
22

33
/***
44
* https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern
55
*/
6-
export function applyMixins<T extends TClass, S extends TClass>(
6+
export function applyMixins<T extends Constructor, S extends Constructor>(
77
derivedCtor: T,
88
constructors: S[]
99
) {
@@ -18,5 +18,5 @@ export function applyMixins<T extends TClass, S extends TClass>(
1818
);
1919
});
2020
});
21-
return derivedCtor;
21+
return derivedCtor as T & { prototype: InstanceType<T & S> };
2222
}

0 commit comments

Comments
 (0)