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

Allow specific service typings for Hook and HookContext #1688

Merged
merged 22 commits into from
Nov 21, 2019
Merged

Allow specific service typings for Hook and HookContext #1688

merged 22 commits into from
Nov 21, 2019

Conversation

deskoh
Copy link
Contributor

@deskoh deskoh commented Nov 17, 2019

The service property of HookContext is of type Service<T>.

export default (options = {}): Hook => {
  return async (context: HookContext<User>) => {
    // No typings for `_create` method (catch-all definition will type unknown fields to `any)
    context.service._create(...)
    return context;
  };
}

This PR is backwards compatible and will allow the following:

import { Service } from 'feathers-mongoose';

export default (options = {}): Hook<User, Service<User>> => {
  return async (context) => {
    // Correct service typings.
    context.service._create(...)
    return context;
  };
}

@daffl
Copy link
Member

daffl commented Nov 21, 2019

I've been meaning to do this, thank you!

@daffl daffl merged commit f5d0ddd into feathersjs:master Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants