-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplyMixins.ts
33 lines (29 loc) · 1008 Bytes
/
applyMixins.ts
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
import {cast} from '../other/cast.js';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function applyMixins(derivedConstructors: any, baseConstructors: any[]) {
baseConstructors.forEach(baseConstructor => {
Object.getOwnPropertyNames(baseConstructor.prototype).forEach(name => {
if (name !== 'constructor') {
derivedConstructors.prototype[name] = baseConstructor.prototype[name];
}
});
});
}
export function applyMixins02<C1, C2>(
derivedConstructors: C1,
baseConstructors: [C2]
): C1 & C2 {
return cast(applyMixins(derivedConstructors, baseConstructors));
}
export function applyMixins03<C1, C2, C3>(
derivedConstructors: C1,
baseConstructors: [C2, C3]
): C1 & C2 & C3 {
return cast(applyMixins(derivedConstructors, baseConstructors));
}
export function applyMixins04<C1, C2, C3, C4>(
derivedConstructors: C1,
baseConstructors: [C2, C3, C4]
): C1 & C2 & C3 & C4 {
return cast(applyMixins(derivedConstructors, baseConstructors));
}