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

Strongly typed context types for operation hook typings #1822

Open
hacksparrow opened this issue Feb 26, 2020 · 0 comments
Open

Strongly typed context types for operation hook typings #1822

hacksparrow opened this issue Feb 26, 2020 · 0 comments

Comments

@hacksparrow
Copy link
Contributor

hacksparrow commented Feb 26, 2020

@bajtos suggested to provide strongly typed context types based on the hook name.

For example:

export interface AccessHookContext<T extends typeof PersistedModel> {
  Model: T;
  query: Filter<T>;
}

export type Listener<Ctx> = (ctx: Ctx, next: (err?: any) => void) => void;

class PersistedModel {
// ...
static observe(operation: 'access', handler: Listener<AccessHookContext>): void;
static observe(operation: 'before save', handler: Listener<BeforeSaveHookContext>): void;
// etc.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants