-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
[feat] [WIP] Store augmentation #1192
[feat] [WIP] Store augmentation #1192
Conversation
…ateNamespacedHelpers
…they are annotated
…tch/CommitOptions
There are some concerns:
|
@HerringtonDarkholme have you looked at https://github.com/championswimmer/vuex-module-decorators ? Decorators allows us write store modules as simple classes. It is very useful and less verbose. |
Closing this PR since this is technically breaking change, we can't introduce this on Vuex 3. However, the fix will be applied to Vuex 4 via #1717. |
Fix #994
Based on #1121
Vuex has added
$store: Store<any>
to Vue instance. This is suboptimal since it doesn't allow users to provide their own store type.By utilizing TS2.8's conditional type, we can write a
PermissiveAny<T>
type which allows users to customize interface withany
as fall-back. It can provide opt-in type safety for store.The store type is parameterized by
State
. By introducing a globalRootState
interface, we can annotate$store
asStore<PermissiveAny<RootState>>
. If users don't augmentRootState
, the $store type is equivalent toStore<any>
. On the other hand, if users do augmentRootState
, the store type will be changed toStore<RootState>
.Effectively, this feature allows users to manual annotate store type, but without breaking existing code.
cc @blake-newman @ktsn