Improve collection/global hook type safety #14842
V1RE
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Currently, collection hooks use T extends TypeWithID = any:
Issues:
Proposal
Improve existing hooks with slug-based generics and export args types, similar to how BeforeOperationHook already works:
This lets TypeScript narrow previousDoc based on operation:
Same pattern for GlobalBeforeChangeHook, GlobalAfterReadHook, etc.
Benefits
Files to Modify
I'm Willing to Implement
I've already built and tested these types in a project. Happy to submit a PR if this approach looks good.
Beta Was this translation helpful? Give feedback.
All reactions