import { createStore } from '@/store/root' ; import Vue from 'vue' ; type Store = ReturnType < typeof createStore > ; type UD = { [ key ] : ( state : Store [ 'state' ] ) => any ; } ; type R < T extends UD > = { [ P in keyof T ] : ( ) => ReturnType < T [ P ] > ; } ; /**
 * inject root state to mapped functions
 */ export function mapComputed < T extends UD [ ] > ( ... sources ) { const dict = sources . reduce ( ( prev , source ) => Object . assign ( prev , source ) , { } ) ; return Object . keys ( dict ) . reduce ( ( prev , key ) => Object . assign ( prev , { [ key ] ( this ) { return dict [ key ] ( this . $store . state ) ; } , } ) , { } ) as any ; }