Skip to content

defineHooks

Source Code | Documentation

Typescript helper function to define hooks with type safety.

ts
  import { 
defineHooks
} from 'feathers-utils/utils';

Type declaration

ts
/**
 * Typescript helper function to define hooks with type safety.
 *
 * @see https://utils.feathersjs.com/utils/define-hooks.html
 */
export declare function defineHooks<
  A extends Application = Application,
  S = {
    find: any
    get: any
    create: any
    update: any
    patch: any
    remove: any
  },
  Options = HookOptions<A, S>,
>(hooks: Options): Options
ArgumentTypeDescription
hooksOptions

When you define hooks in feathers like this:

ts
export default {
  before: {
    // ...
  },
  // ...
};

you don't have autocompletion. Instead, you can use defineHooks to define type-safe hooks:

ts
import { defineHooks } from "feathers-utils/utils";
export default defineHooks({
  before: {
    // ...
  },
  // ...
});

Released under the MIT License.