Description
What problem does this feature solve?
With the introduction of inference from template strings in TS 4.1.0 it will finally be possible to make Vuex completely type safe (validating all types, paths for commit/dispatch/modules/getters, etc).
Are there existing plans to add complete type support with the release of Vuex 4?
For reference, I've created the following project:
https://github.com/ClickerMonkey/vuex-typescript-interface
The only adjustment to the existing type system is that it would require an interface for each module and the root state - so that the modules and root state are aware of each others types. It could be optional like it currently is.
Here's how the new TS feature would solve the remaining challenge with complete type support with Vuex:
type GetEmbeddedType<O, Path extends string> =
Path extends `${infer A}/${infer B}`
? A extends keyof O
? B extends keyof O[A]
? O[A][B]
: never
: never
: never;
interface State {
prop: {
innerProp: number;
}
};
type InnerPropType = GetEmbeddedType<State, 'prop/innerProp'>; // number!!
What does the proposed API look like?
Similar to what exists now, just full type support to validate types, the existence of all mutations and dispatches, and communications between the root store and it' modules.