You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While trying to specify the types to get auto-suggestions when using the store within action and getter functions, I tried defining the types explicitly. My actual store as many actions/getters, so it made sense to separate these into different files, but I still wanted the good DX from VSCODE. Trying to make that happen, I found an issue with the type of the getter input. Add the following to a vue3+typescript project.
I would expect that StoreType should work as the input to both getters and the $patch function input without error
Actual behavior
I see this error:
TS2344: Type 'Getters' does not satisfy the constraint '_GettersTree<State>'.
Property 'doubleCount' is incompatible with index signature.
Type '(state: StoreType) => number' is not assignable to type '(() => any) | ((state: { count: number; name: string; } & PiniaCustomStateProperties<State>) => any)'.
Type '(state: StoreType) => number' is not assignable to type '() => any'.
Additional information
Note, I can change the type of the getter function from "StoreType" to "State" and it will compile, but other getters don't show up as suggestions in VSCode and if I try to use them, typescript complains.
However, if I debug or use base javascript, I can access other getters from within the getter function or action functions as properties of state/this, and they return the expected values (not the getter functions)
I have a similar problem using a $patch with a function if I try to make the argument "StoreType" instead of "State" and again, I should be able to access getters from within a patch function. (right?)
So, what should the type of the input to the getter function and $patch function be. I would assume:
State & PiniaCustomStateProperties<State> & GetterProperties<Getters>
where
type GetterProperties<Getters extends {[KeyType: string]: (...args: any[]) => any}> = {
[key in (keyof Getters)]: ReturnType<Getters[key]>
}
The text was updated successfully, but these errors were encountered:
vuejs
locked and limited conversation to collaborators
Dec 1, 2022
Reproduction
See Store Below
Steps to reproduce the bug
While trying to specify the types to get auto-suggestions when using the store within action and getter functions, I tried defining the types explicitly. My actual store as many actions/getters, so it made sense to separate these into different files, but I still wanted the good DX from VSCODE. Trying to make that happen, I found an issue with the type of the getter input. Add the following to a vue3+typescript project.
Expected behavior
I would expect that StoreType should work as the input to both getters and the $patch function input without error
Actual behavior
I see this error:
Additional information
Note, I can change the type of the getter function from "StoreType" to "State" and it will compile, but other getters don't show up as suggestions in VSCode and if I try to use them, typescript complains.
However, if I debug or use base javascript, I can access other getters from within the getter function or action functions as properties of state/this, and they return the expected values (not the getter functions)
I have a similar problem using a $patch with a function if I try to make the argument "StoreType" instead of "State" and again, I should be able to access getters from within a patch function. (right?)
So, what should the type of the input to the getter function and $patch function be. I would assume:
where
The text was updated successfully, but these errors were encountered: