Browse Source

refactor: updates WithoutId and PartialWithoutId type

e22m4u 1 month ago
parent
commit
04ef020dec
1 changed files with 8 additions and 7 deletions
  1. 8 7
      src/repository/repository.d.ts

+ 8 - 7
src/repository/repository.d.ts

@@ -68,7 +68,7 @@ export declare class Repository<
    */
   replaceById(
     id: IdType,
-    data: WithoutId<IdName, FlatData>,
+    data: WithoutId<FlatData, IdName>,
     filter?: ItemFilterClause,
   ): Promise<FlatData>;
 
@@ -90,7 +90,7 @@ export declare class Repository<
    * @param where
    */
   patch(
-    data: PartialWithoutId<IdName, Data>,
+    data: PartialWithoutId<Data, IdName>,
     where?: WhereClause,
   ): Promise<number>;
 
@@ -103,7 +103,7 @@ export declare class Repository<
    */
   patchById(
     id: IdType,
-    data: PartialWithoutId<IdName, Data>,
+    data: PartialWithoutId<Data, IdName>,
     filter?: ItemFilterClause,
   ): Promise<FlatData>;
 
@@ -161,16 +161,17 @@ export declare class Repository<
 /**
  * Removes id field.
  */
-type WithoutId<IdName extends string, Data extends object> = Flatten<
+type WithoutId<Data extends object, IdName extends string = 'id'> = Flatten<
   Omit<Data, IdName>
 >;
 
 /**
  * Makes fields as optional and remove id field.
  */
-type PartialWithoutId<IdName extends string, Data extends object> = Flatten<
-  Partial<Omit<Data, IdName>>
->;
+type PartialWithoutId<
+  Data extends object,
+  IdName extends string = 'id',
+> = Flatten<Partial<Omit<Data, IdName>>>;
 
 /**
  * Makes the required id field as optional.