@zwa73/utils 1.0.74 → 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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.74",
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
  }