This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: improve type and autocompletion in stores #643
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Total Coverage: 93.23% Coverage Report
|
Total Coverage: 97.35% Coverage Report
|
carlossantos74
approved these changes
Apr 18, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
Good job with store types.
🎉 This PR is included in version 6.1.0-lab.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 6.1.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 6.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before:
After:
What was crucial to achieve this was the line
type Subject<T extends (...args: any[]) => any, K extends keyof ReturnType<T>> = ReturnType<T>[K]
. Basically,ReturnType<T>
is a type with every possible item in the store, whileK
is the name of the item. Since they're all of the typePublicSubject
, acessing the type of the value is just a matter of indexing with ['value'] at the end:Subject['value']
. Good stuff.Requiring the id to merely subscribe to an event of a field made subscribing ugly and complicated if the person decides to register a field later, so now only the event name is required, and the callback is called with the fieldId in it in case the user wants to filter something.