npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vue-typescript-util

v0.0.2

Published

write vue with typescript

Downloads

7

Readme

vue-typescript-util

write vue with type check
this module only work with /.tsx?/ file

important

to make VueComponent active.
you have to create a jsx.d.ts file in project root like this

you may need this => how it worked and preview

exposed

  • vue
    • VueComponent
  • vuex
    • MakeVuexModule
    • BindToRootMutation
    • BindToRootActions
    • InjectStore

usage

see folder demo

  • VueComponent<Props={}, store extends Store<any> = Store<any>>
    with vue-class-component you can use type checking
    import Component from "vue-class-component";
    import { Prop } from "vue-property-decorator"
    import { VueComponent } from "vue-typescript-util";
    import { CreateElement } from "vue";
    
    export type MyComponentPropsType = {
      name:string;
      title?:string;
    }
    //define a component MyComponent
    @Component
    export class MyComponent extends VueComponent<MyComponentPropsType>{
      @Prop()
      name:string;
      @Prop()
      title:string;
      render(h: CreateElement){
    
      }
    }
    //use MyComponent in MyComponent1
    @Component
    export class MyComponent1 extends VueComponent{
      render(h: CreateElement){
        // type ckeck error 
        return <MyComponent></MyComponent>
      }
    }

about vuex

  • define vuex module State

    export type EventState = {
      name: string;
    }
    const state = {
      name: ''
    }
    // declartion migration globalState
    declare module "../.." {
      interface AppStoreStates {
        event: EventState
      }
    }
  • define vuex module getters

    type EventGetters = {
      // name : return type
      nameLength: number;
    }
    const getters: GetterModule<EventGetters, EventState> = {
      nameLength(state) {
        return state.name.length;
      }
    }
    //AppStoreGetters globalGetters type
    declare module "../.." {
      // common module
      interface AppStoreGetters extends EventGetters { }
      // namespaced module
      interface AppStoreGetters {
        event:EventGetters
      }
    }
  • define vuex mutations

    type EventMutations = {
      setName: string
    }
    const mutations: MutationModule<EventMutations, EventState> = {
      setName(state, payload) {
        state.name = payload;
      }
    }
    // AppStoreMutations global mutation type
    declare module "../.." {
      interface AppStoreMutations {
        // EventModule result of MakeVuexModule
        event: typeof EventModule.mutations
      }
    }
  • define vuex Actions

      type EventActions = {
        clearName: boolean
      }
    
      const actions: ActionModule<EventActions, EventState, EventGetters> = {
        clearName(context, payload) {
          if (payload) {
            // commit from root
            context.commit(StoreMutations.event.setName, '', { root: true })
          } else {
            // commit from module
            context.commit(ModuleMutations.setName, '')
            console.info(`commit from module`)
          }
        }
      }
      declare module "../.." {
        interface AppStoreActions {
          // EventModule result of MakeVuexModule
          event: typeof EventModule.actions
        }
      }
  • define vuex module
    MakeVuexModule(moduleTree:_moduleTree,moduleName: string,namespace: boolean = false)

    const moduleInstance = {
      state,
      getters,
      mutations,
      actions
    }
    // no namespaced
    const EventModule = MakeVuexModule(moduleInstance, 'event',false);
    const ModuleMutations = EventModule.moduleMutations;
    // wrap of BindToRootActions
    registeActions(EventModule.actions, 'event');
    // wrap of BindToRootMutation
    registeMutations(EventModule.mutations, 'event')
    export default EventModule.module;//this is vuex module
  • global store
    type define global Store

    export interface AppStoreStates { }
    export interface AppStoreGetters { }
    export interface AppStoreActions { }
    export interface AppStoreMutations { }
    export interface AppStore extends InjectStore<AppStoreStates, AppStoreGetters> { }

    define global Actions and Mutaions , then we can use declaration migration to enhance them;

    export const StoreActions: AppStoreActions = {} as any;
    export const StoreMutations: AppStoreMutations = {} as any;
    //wrap of Bindings to StoreActions/StoreMutations
    export function registeActions<Actions = any>(actions: ActionNames<Actions>, namespace: string) {
      BindToRootActions(actions, namespace, StoreActions)
    }
    export function registeMutations<Mutations = any>(mutations: MutationNames<Mutations>, namespace: string) {
      BindToRootMutation(mutations, namespace, StoreMutations);
    }

    type define utils of GetterModule,MutationModule,ActionModule

    export type GetterModule<Typedef, State> = AbstractGetterModule<Typedef, State, AppStoreStates, AppStoreGetters>;
    export type MutationModule<Typedef, State> = AbstractMutationModule<Typedef, State>;
    export type ActionModule<Typedef, State, Getters> = AbstractActionModule<Typedef, State, Getters, AppStoreStates, AppStoreGetters>;

    define vuex store and InjectIt

    import dom from './modules/dom';
    import event from './modules/event';
    
    const store: AppStore = new Vuex.Store({
      modules: {
        dom,
        event
      }
    }) as any;
    InjectStore(store);
    // after 
    //you can use store.Commit with StoreMutations
    //you can use store.Dispatch with StoreMutations
    export { store }
    
    // define a class Injected AppStore
    export interface PageComponent<Props = {}> extends VueComponent<Props, AppStore> { }
    export class PageComponent<Props = {}> extends VueComponent<Props, AppStore>{ }