@zwa73/utils 1.0.73 → 1.0.75

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.
@@ -12,7 +12,7 @@ export declare namespace UtilFunc {
12
12
  * @param defaultVal - 默认值
13
13
  * @returns 最终值
14
14
  */
15
- function initField<T>(obj: Record<string, T>, field: string, defaultVal: T): T;
15
+ function initField<T extends object, K extends keyof T>(obj: T, field: K, defaultVal: T[K]): T[K];
16
16
  /**生成一串uuid
17
17
  * @returns uuid
18
18
  */
@@ -213,26 +213,27 @@ var UtilFunc;
213
213
  for (const fd of fields) {
214
214
  if (compObj[fd] !== undefined)
215
215
  UtilLogger_1.SLogger.warn(`field: ${fd} 已存在于基础类中, 混入可能导致类型问题, 如需覆盖, 请使用 ${key}=val`);
216
- Object.defineProperty(compObj, fd, {
217
- get: () => compObj[key][fd],
218
- set: (value) => { compObj[key][fd] = value; },
219
- enumerable: true,
220
- //writable: true ,
221
- configurable: true
222
- });
223
- //if(typeof mixin[fd] === 'function') {
224
- // compObj[fd] = (...args: any[]) => compObj[key][fd](...args);
225
- // //(compObj as any)[fd] = (...args: any[]) => (mixin[fd] as any).apply(mixin, args);
226
- // //(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
227
- //} else {
228
- // Object.defineProperty(compObj, fd, {
229
- // get: ()=>compObj[key][fd],
230
- // set: (value)=>{compObj[key][fd] = value},
231
- // enumerable:true ,
232
- // //writable: true ,
233
- // configurable: true
234
- // });
235
- //}
216
+ //Object.defineProperty(compObj, fd, {
217
+ // get: ()=>compObj[key][fd],
218
+ // set: (value)=>{compObj[key][fd] = value},
219
+ // enumerable:true ,
220
+ // //writable: true ,
221
+ // configurable: true
222
+ //});
223
+ if (typeof mixin[fd] === 'function') {
224
+ compObj[fd] = (...args) => compObj[key][fd](...args);
225
+ //(compObj as any)[fd] = (...args: any[]) => (mixin[fd] as any).apply(mixin, args);
226
+ //(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
227
+ }
228
+ else {
229
+ Object.defineProperty(compObj, fd, {
230
+ get: () => compObj[key][fd],
231
+ set: (value) => { compObj[key][fd] = value; },
232
+ enumerable: true,
233
+ //writable: true ,
234
+ configurable: true
235
+ });
236
+ }
236
237
  }
237
238
  return compObj;
238
239
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.73",
3
+ "version": "1.0.75",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -19,11 +19,11 @@ export function getTime(): number {
19
19
  * @param defaultVal - 默认值
20
20
  * @returns 最终值
21
21
  */
22
- export function initField<T>(
23
- obj: Record<string, T>,
24
- field: string,
25
- defaultVal: T
26
- ): T {
22
+ export function initField<T extends object,K extends keyof T>(
23
+ obj: T,
24
+ field: K,
25
+ defaultVal: T[K]
26
+ ): T[K] {
27
27
  if (!(field in obj)) obj[field] = defaultVal;
28
28
  return obj[field];
29
29
  }
@@ -231,26 +231,26 @@ export function composeClassPart
231
231
  for(const fd of fields){
232
232
  if(compObj[fd]!==undefined)
233
233
  SLogger.warn(`field: ${fd as string} 已存在于基础类中, 混入可能导致类型问题, 如需覆盖, 请使用 ${key}=val`);
234
- Object.defineProperty(compObj, fd, {
235
- get: ()=>compObj[key][fd],
236
- set: (value)=>{compObj[key][fd] = value},
237
- enumerable:true ,
238
- //writable: true ,
239
- configurable: true
240
- });
241
- //if(typeof mixin[fd] === 'function') {
242
- // compObj[fd] = (...args: any[]) => compObj[key][fd](...args);
243
- // //(compObj as any)[fd] = (...args: any[]) => (mixin[fd] as any).apply(mixin, args);
244
- // //(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
245
- //} else {
246
- // Object.defineProperty(compObj, fd, {
247
- // get: ()=>compObj[key][fd],
248
- // set: (value)=>{compObj[key][fd] = value},
249
- // enumerable:true ,
250
- // //writable: true ,
251
- // configurable: true
252
- // });
253
- //}
234
+ //Object.defineProperty(compObj, fd, {
235
+ // get: ()=>compObj[key][fd],
236
+ // set: (value)=>{compObj[key][fd] = value},
237
+ // enumerable:true ,
238
+ // //writable: true ,
239
+ // configurable: true
240
+ //});
241
+ if(typeof mixin[fd] === 'function') {
242
+ compObj[fd] = (...args: any[]) => compObj[key][fd](...args);
243
+ //(compObj as any)[fd] = (...args: any[]) => (mixin[fd] as any).apply(mixin, args);
244
+ //(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
245
+ } else {
246
+ Object.defineProperty(compObj, fd, {
247
+ get: ()=>compObj[key][fd],
248
+ set: (value)=>{compObj[key][fd] = value},
249
+ enumerable:true ,
250
+ //writable: true ,
251
+ configurable: true
252
+ });
253
+ }
254
254
  }
255
255
  return compObj;
256
256
  }