@etsoo/shared 1.1.60 → 1.1.61

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,13 @@ 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, Editing extends boolean, D extends string = 'id'> = Editing extends true ? Partial<T> & {
126
+ [key in D]: number | string;
127
+ } & {
126
128
  changedFields?: string[];
127
- };
129
+ } : T;
128
130
  /**
129
131
  * Key collection, like { key1: {}, key2: {} }
130
132
  */
@@ -120,11 +120,13 @@ 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, Editing extends boolean, D extends string = 'id'> = Editing extends true ? Partial<T> & {
126
+ [key in D]: number | string;
127
+ } & {
126
128
  changedFields?: string[];
127
- };
129
+ } : T;
128
130
  /**
129
131
  * Key collection, like { key1: {}, key2: {} }
130
132
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.60",
3
+ "version": "1.1.61",
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,17 @@ 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
+ Editing extends boolean,
163
+ D extends string = 'id'
164
+ > = Editing extends true
165
+ ? Partial<T> & { [key in D]: number | string } & {
166
+ changedFields?: string[];
167
+ }
168
+ : T;
164
169
 
165
170
  /**
166
171
  * Key collection, like { key1: {}, key2: {} }