import { computed , ComputedRef , InjectionKey } from '@vue/composition-api' ; import type { Store } from 'vuex' ; import { getCurrentInstance } from './utils' ; param property param makeComputed export const wrapProperty = < K extends keyof NonNullable < ReturnType < typeof getCurrentInstance > > , T extends boolean = true > ( property , makeComputed ? ) => { return ( ) : T extends true ? ComputedRef < NonNullable < ReturnType < typeof getCurrentInstance > > [ K ] > : NonNullable < ReturnType < typeof getCurrentInstance > > [ K ] => { const vm = getCurrentInstance ( ) ; if ( ! vm ) throw new Error ( 'This must be called within a setup function.' ) ; return makeComputed !== false ? ( computed ( ( ) => vm [ property ] ) as any ) : vm [ property ] ; } ; } ; example export const useRouter = wrapProperty ( '$router' , false ) ; example export const useRoute = wrapProperty ( '$route' ) ; example export const useStore = < S > ( key ? ) : Store < S > => { const vm = getCurrentInstance ( ) ; if ( ! vm ) throw new Error ( 'This must be called within a setup function.' ) ; return vm . $store ; } ;