@etsoo/shared 1.1.60 → 1.1.62

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.
@@ -120,11 +120,15 @@ export declare namespace DataTypes {
120
120
  type IdType = number | string;
121
121
  /**
122
122
  * Add or edit conditional type for same data model
123
- * Dynamic add changedFields for editing case
123
+ * Dynamic add id and changedFields for editing case
124
124
  */
125
- type AddOrEditType<T, Editing extends boolean> = (Editing extends true ? T : Partial<T>) & {
125
+ type AddOrEditType<T extends object, E extends boolean, // Editing or not
126
+ I extends IdType = number, // Id type, default is number
127
+ D extends string = 'id'> = E extends true ? Partial<T> & {
128
+ [key in D]: I;
129
+ } & {
126
130
  changedFields?: string[];
127
- };
131
+ } : T;
128
132
  /**
129
133
  * Key collection, like { key1: {}, key2: {} }
130
134
  */
@@ -120,11 +120,15 @@ export declare namespace DataTypes {
120
120
  type IdType = number | string;
121
121
  /**
122
122
  * Add or edit conditional type for same data model
123
- * Dynamic add changedFields for editing case
123
+ * Dynamic add id and changedFields for editing case
124
124
  */
125
- type AddOrEditType<T, Editing extends boolean> = (Editing extends true ? T : Partial<T>) & {
125
+ type AddOrEditType<T extends object, E extends boolean, // Editing or not
126
+ I extends IdType = number, // Id type, default is number
127
+ D extends string = 'id'> = E extends true ? Partial<T> & {
128
+ [key in D]: I;
129
+ } & {
126
130
  changedFields?: string[];
127
- };
131
+ } : T;
128
132
  /**
129
133
  * Key collection, like { key1: {}, key2: {} }
130
134
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.60",
3
+ "version": "1.1.62",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -60,8 +60,8 @@
60
60
  "eslint": "^8.25.0",
61
61
  "eslint-config-airbnb-base": "^15.0.0",
62
62
  "eslint-plugin-import": "^2.26.0",
63
- "jest": "^29.1.2",
64
- "jest-environment-jsdom": "^29.1.2",
63
+ "jest": "^29.2.0",
64
+ "jest-environment-jsdom": "^29.2.0",
65
65
  "ts-jest": "^29.0.3",
66
66
  "typescript": "^4.8.4"
67
67
  }
package/src/DataTypes.ts CHANGED
@@ -155,12 +155,18 @@ export namespace DataTypes {
155
155
 
156
156
  /**
157
157
  * Add or edit conditional type for same data model
158
- * Dynamic add changedFields for editing case
158
+ * Dynamic add id and changedFields for editing case
159
159
  */
160
160
  export type AddOrEditType<
161
- T,
162
- Editing extends boolean
163
- > = (Editing extends true ? T : Partial<T>) & { changedFields?: string[] };
161
+ T extends object,
162
+ E extends boolean, // Editing or not
163
+ I extends IdType = number, // Id type, default is number
164
+ D extends string = 'id' // Id field name
165
+ > = E extends true
166
+ ? Partial<T> & { [key in D]: I } & {
167
+ changedFields?: string[];
168
+ }
169
+ : T;
164
170
 
165
171
  /**
166
172
  * Key collection, like { key1: {}, key2: {} }