@zwa73/utils 1.0.69 → 1.0.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/UtilInterfaces.d.ts
CHANGED
|
@@ -101,10 +101,10 @@ export type MethodsThisAs<Methods, T> = {
|
|
|
101
101
|
*/
|
|
102
102
|
export declare function assertThisAs<Self, T>(prototype: MethodsThisAs<Self, T>): void;
|
|
103
103
|
/**可自动混入的类型 */
|
|
104
|
-
export type
|
|
104
|
+
export type Mixinable<Mixin> = {
|
|
105
105
|
/**可混入的字段 */
|
|
106
106
|
readonly MIXIN_FIELDS: ReadonlyArray<keyof Mixin>;
|
|
107
107
|
};
|
|
108
|
-
|
|
109
|
-
export type ComposedMixinable<B extends object, Ms extends Array<unknown>> = Ms extends [infer M, ...infer Rest] ? M extends
|
|
108
|
+
/**自动组合可混入的类 */
|
|
109
|
+
export type ComposedMixinable<B extends object, Ms extends Array<unknown>> = Ms extends [infer M, ...infer Rest] ? M extends Mixinable<M> ? ComposedMixinable<ComposedClassPart<B, M, M['MIXIN_FIELDS'][number]>, Rest> : B : B;
|
|
110
110
|
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare class A implements
|
|
1
|
+
import { Mixinable } from "..";
|
|
2
|
+
declare class A implements Mixinable<A> {
|
|
3
3
|
private num;
|
|
4
4
|
getNum: () => number;
|
|
5
5
|
/**A的函数 */
|
|
6
6
|
getA: () => this;
|
|
7
7
|
MIXIN_FIELDS: readonly ["getNum", "getA"];
|
|
8
8
|
}
|
|
9
|
-
declare class B implements
|
|
9
|
+
declare class B implements Mixinable<B> {
|
|
10
10
|
private text;
|
|
11
11
|
getText: () => string;
|
|
12
12
|
/**B的函数 */
|
package/package.json
CHANGED
package/src/UtilFunctions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as crypto from "crypto";
|
|
2
|
-
import { ComposedClass, ComposedClassMult, ComposedClassPart, ComposedMixinable, FuncPropNames, JToken,
|
|
2
|
+
import { ComposedClass, ComposedClassMult, ComposedClassPart, ComposedMixinable, FuncPropNames, JToken, Mixinable, PromiseProcFn, PromiseStat, PromiseVerifyFn } from "@src/UtilInterfaces";
|
|
3
3
|
import * as cp from "child_process";
|
|
4
4
|
import { SLogger } from "@src/UtilLogger";
|
|
5
5
|
|
|
@@ -256,7 +256,7 @@ export function composeMixinable
|
|
|
256
256
|
M1, M2, M3,M4, M5, M6,M7, M8, M9>
|
|
257
257
|
(base:B,m1?:M1,m2?:M2,m3?:M3,m4?:M4,m5?:M5,m6?:M6,m7?:M7,m8?:M8,m9?:M9):
|
|
258
258
|
ComposedMixinable<B,[M1,M2,M3,M4,M5,M6,M4,M8,M9]>
|
|
259
|
-
export function composeMixinable<Base extends object, Mixin extends
|
|
259
|
+
export function composeMixinable<Base extends object, Mixin extends Mixinable<Mixin>>(base:Base,...mixins:Mixin[]){
|
|
260
260
|
let out = base;
|
|
261
261
|
for(const mixin of mixins)
|
|
262
262
|
out = composeClassPart(base,mixin,...mixin.MIXIN_FIELDS);
|
package/src/UtilInterfaces.ts
CHANGED
|
@@ -158,15 +158,15 @@ export type MethodsThisAs<Methods, T> = {
|
|
|
158
158
|
export function assertThisAs<Self,T>(prototype: MethodsThisAs<Self, T>) {}
|
|
159
159
|
|
|
160
160
|
/**可自动混入的类型 */
|
|
161
|
-
export type
|
|
161
|
+
export type Mixinable<Mixin> = {
|
|
162
162
|
/**可混入的字段 */
|
|
163
163
|
readonly MIXIN_FIELDS:ReadonlyArray<keyof Mixin>
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
/**自动组合可混入的类 */
|
|
167
167
|
export type ComposedMixinable<B extends object, Ms extends Array<unknown>> =
|
|
168
168
|
Ms extends [infer M, ...infer Rest]
|
|
169
|
-
? M extends
|
|
169
|
+
? M extends Mixinable<M>
|
|
170
170
|
? ComposedMixinable<ComposedClassPart<B,M,M['MIXIN_FIELDS'][number]>,Rest>
|
|
171
171
|
: B
|
|
172
172
|
: B
|
package/src/test/composeTest.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Mixinable, UtilFP, UtilFunc, assertThisAs } from ".."
|
|
2
2
|
|
|
3
|
-
class A implements
|
|
3
|
+
class A implements Mixinable<A>{
|
|
4
4
|
private num = 1;
|
|
5
5
|
getNum = ()=>this.num;
|
|
6
6
|
/**A的函数 */
|
|
7
7
|
getA=()=>this;
|
|
8
8
|
MIXIN_FIELDS =['getNum','getA'] as const;
|
|
9
9
|
}
|
|
10
|
-
class B implements
|
|
10
|
+
class B implements Mixinable<B>{
|
|
11
11
|
private text = "B的text";
|
|
12
12
|
getText = ()=>this.text;
|
|
13
13
|
/**B的函数 */
|