DEV Community

Discussion on: Vuex + TypeScript

Collapse
 
3vilarthas profile image
Andrew • Edited

Hey Sergej, Thanks. You have to manually create MODULE_NAME/MUTATION_TYPE mappings by now. But if you are using TS 4.1 you can use Template Literal Types.

Here is the snippet from the helper library I am developing right now:

type Namespaced<T, N extends string> = {
  [P in keyof T & string as `${N}/${P}`]: T[P]
}

type NamespacedMutations = Namespaced<ArticleModuleMutations, "atricle">
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
sergejpopov profile image
Sergej

I see, nice trick, thanks, Andrew!