Type Alias: HookableEvents<T>
ts
type HookableEvents<T> = {
[K in keyof T]: T[K] extends (args: infer P) => boolean | void
? [callbackArgs: [...P], cleanupCallbackArgs: [error: Error | null, ...P]]
: never;
};Transforms emit validators or emit functions into hookable event types.
Each event gets converted to a tuple with two signatures:
- Hook handler signature - receives the original event parameters
- Cleanup function signature - receives Error | null plus the original parameters
Type Parameters
| Type Parameter | Description |
|---|---|
T extends EmitValidators | EmitFunctions<EmitValidators> | The emit validators or emit functions object type |
Example
typescript
const emits = {
saving: (model: BaseModel) => true,
finding: (query: QueryBuilder) => true,
};
type Events = HookableEvents<typeof emits>;
// {
// saving: [
// [BaseModel], // for hook handler
// [error: Error | null, BaseModel], // for cleanup function
// ],
// finding: [
// [QueryBuilder], // for hook handler
// [error: Error | null, QueryBuilder], // for cleanup function
// ]
// }