-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Plugins: Expose DefineStoreOptionsBase
in PiniaCustomProperties
#1247
Comments
I don't understand what change you are suggesting. Can you open a PR with your proposal instead? |
I currently don't have time, but basically when you use the above plugin, there is no way to get to the actual types of the stores that have been defined in the stores option, because the const useUserStore = defineStore('user', {
state: () => ({
name: 'Max Power',
}),
getters: {
getName (state) {
return state.name;
},
},
});
const useTestStore = defineStore('test', {
stores: {
// userStore type is known here
userStore: useUserStore,
},
actions: {
log () {
// userStore type is unknown here
console.log(this.stores.userStore.getName);
},
},
}); It would be great if the types in |
I see. I don't think this is actually feasible even with a small breaking change. Let's give it some time so people can share their ideas. |
@posva I have a case which justifies adding I'm using options stores like this: defineStore('name', {
state: () => ({
controllers: initAbortController(
'update',
'updateList',
),
}),
actions: {
update() {},
updateList(){}
}
} Where
If I could access
Like this: defineStore('name', {
actions: {
update() {},
updateList(){}
}
},
controllers: ['update', 'updateList'] Currently I can't do this because of the related type issue. Typings for this would look like this if declare module 'pinia' {
export interface DefineStoreOptionsBase<S, Store> {
controllers?: Array<keyof StoreActions<Store>;
}
export interface PiniaCustomProperties {
// ↓ No access to store options here
controllers?: DefineStoreOptionsBase['controllers']
}
} |
What problem is this solving
I wrote a plugin to solve #625. This is basically working, but the types of the stores defined in the new stores option in
DefineStoreOptionsBase
are not accessible insidePiniaCustomProperties
.Proposed solution
If the store options would be accessible inside
PiniaCustomProperties
, the actual types of the concrete stores could be accessed withthis.stores
.Describe alternatives you've considered
No response
The text was updated successfully, but these errors were encountered: