Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: the type of the beforeBulkDestroy hander's options attribute is BulkCreateOptions instead of BulkDestroyOptions #17246

Open
kf6kjg opened this issue Apr 3, 2024 · 0 comments
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet

Comments

@kf6kjg
Copy link
Contributor

kf6kjg commented Apr 3, 2024

In my use case I needed to access the where attribute of the options property that's passed to the callback/handler passed to beforeBulkDestroy. However since that's described as an BulkCreateOptions not a BulkDestroyOptions, that isn't possible when using the inferred type in TypeScript.

Here is the patch that solved my problem:

diff --git a/node_modules/sequelize/types/model.d.ts b/node_modules/sequelize/types/model.d.ts
index 7ab36db..a0665d4 100644
--- a/node_modules/sequelize/types/model.d.ts
+++ b/node_modules/sequelize/types/model.d.ts
@@ -1091,6 +1091,13 @@ export interface BulkCreateOptions<TAttributes = any> extends Logging, Transacti
   conflictAttributes?: Array<keyof TAttributes>;
 }
 
+/**
+ * Options for Model.bulkDestroy method
+ */
+export interface BulkDestroyOptions<TAttributes = any> extends BulkCreateOptions<TAttributes> {
+  where?: WhereOptions;
+}
+
 /**
  * The options passed to Model.destroy in addition to truncate
  */
@@ -2770,10 +2777,10 @@ export abstract class Model<TModelAttributes extends {} = any, TCreationAttribut
    */
   public static beforeBulkDestroy<M extends Model>(
     this: ModelStatic<M>,
-    name: string, fn: (options: BulkCreateOptions<Attributes<M>>) => HookReturn): void;
+    name: string, fn: (options: BulkDestroyOptions<Attributes<M>>) => HookReturn): void;
   public static beforeBulkDestroy<M extends Model>(
     this: ModelStatic<M>,
-    fn: (options: BulkCreateOptions<Attributes<M>>) => HookReturn
+    fn: (options: BulkDestroyOptions<Attributes<M>>) => HookReturn
   ): void;
 
   /**

However I didn't dig to see if there's a better implementation, or if there's more to change, this just minimally solved my problem.

@github-actions github-actions bot added the pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet label Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet
Projects
None yet
Development

No branches or pull requests

1 participant