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

fix: post hook 'res' param with type any #11924

Merged
merged 3 commits into from
Jun 15, 2022

Conversation

GCastilho
Copy link
Contributor

-- Fix post hook using PostMiddlewareFunction generic type without passing T to ResType

Summary

The type for the 'post hook' middleware is passing the T only to the first argument of the PostMiddlewareFunction (the this type), not to the second, resulting on the ResType defaulting to any

Examples

type User = {
  name: string
}
const userSchema = new Schema<User>({ ... })

# Before
userSchema.post('validate', (doc, next) => {
  // doc has type 'any'
})

# After
userSchema.post('validate', (doc, next) => {
  // doc has type 'User'
})

-- Fix post hook using PostMiddlewareFunction generic type without passing T to ResType
@Uzlopak
Copy link
Collaborator

Uzlopak commented Jun 11, 2022

Can you add some typings tests please?

-- Add Utility Type do extract type from Aggregate class
-- Fix ResType type for aggregate hook
-- Add tests for post 'save' and post 'aggregate' hooks
@GCastilho
Copy link
Contributor Author

@Uzlopak I've added some tests for the types. Please let me know if you think it needs more or if there is a problem with them

Copy link
Collaborator

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vkarpov15
Copy link
Collaborator

In principle this looks ok, but the TS benchmark results don't look so good. Although I suspect they may be better after #11925 .

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve and merge this for now, so I can double check the TypeScript benchmark. PR looks good pending benchmark results.

@vkarpov15 vkarpov15 merged commit 6d91d94 into Automattic:master Jun 15, 2022
@vkarpov15 vkarpov15 added this to the 6.3.8 milestone Jun 15, 2022
@GCastilho GCastilho deleted the fix/post-hook-missing-t branch June 18, 2022 14:16
@GCastilho
Copy link
Contributor Author

Thank you :D

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.

None yet

3 participants