[TS] Fix strict type on chain callback, widgetInput (#3727)

This commit is contained in:
filtered
2025-05-02 11:29:43 +10:00
committed by GitHub
parent 2c75948ab9
commit c82401c61c
2 changed files with 23 additions and 7 deletions

View File

@@ -1,3 +1,19 @@
/**
* Shorthand for {@link Parameters} of optional callbacks.
*
* @example
* ```ts
* const { onClick } = CustomClass.prototype
* CustomClass.prototype.onClick = function (...args: CallbackParams<typeof onClick>) {
* const r = onClick?.apply(this, args)
* // ...
* return r
* }
* ```
*/
export type CallbackParams<T extends ((...args: any) => any) | undefined> =
Parameters<Exclude<T, undefined>>
/**
* Chain multiple callbacks together.
*
@@ -14,6 +30,6 @@ export const useChainCallback = <
) => {
return function (this: O, ...args: Parameters<T>) {
originalCallback?.call(this, ...args)
callbacks.forEach((callback) => callback.call(this, ...args))
for (const callback of callbacks) callback.call(this, ...args)
}
}