Using Typescript, I aim to make use of my string enumeration:
export const enum MutationKeys {
registerUser = 'registration/REGISTER',
registerUserCompleted = 'registration/REGISTER_COMPLETED'
}
This allows the string values to impose type-checking restrictions on an object like this:
const mutations: IDictionary<VuexMutation> = {
['registration/REGISTER'](state, payload) {
state.registration = {
meta: {
serverValidated: false
},
value: payload
};
},
['registration/REGISTER_COMPLETED'](state) {
state.registration.meta.serverValidated = true;
}
};
The
IDictionary<VueMutation>
interface in the example above enables me to define the value type for the object, while still allowing for any string index.