Skip to content

Commit

Permalink
Add a type variable to Hook (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Derugon authored Dec 11, 2023
1 parent e65124c commit ad5747a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions mw/hook.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@
*
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook
*/
interface Hook {
interface Hook<T extends any[] = any[]> {
/**
* Register a hook handler
*
* @param {...Function} handler Function to bind.
* @chainable
*/
add(...handler: Array<(...args: any[]) => any>): Hook;
add(...handler: Array<(...data: T) => any>): this;

/**
* Run a hook.
*
* @param {*} data
* @chainable
*/
fire(data?: any): Hook;
fire(...data: T): this;

/**
* Unregister a hook handler
*
* @param {...Function} handler Function to unbind.
* @chainable
*/
remove(handler: (...args: any[]) => any): Hook;
remove(...handler: Array<(...data: T) => any>): this;
}

declare global {
Expand All @@ -76,7 +76,7 @@ declare global {
* @member mw
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook
*/
function hook(event: string): Hook;
function hook<T extends any[] = any[]>(event: string): Hook<T>;
}
}

Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"no-padding": false,
"no-unnecessary-qualifier": false,
"unified-signatures": false,
"no-redundant-jsdoc": false
"no-redundant-jsdoc": false,
"no-unnecessary-generics": false
}
}

0 comments on commit ad5747a

Please sign in to comment.