{"id":13683770,"url":"https://github.com/ktsn/vuex-type-helper","last_synced_at":"2025-04-12T13:36:36.790Z","repository":{"id":55668305,"uuid":"101460788","full_name":"ktsn/vuex-type-helper","owner":"ktsn","description":"Type level helper to ensure type safety in Vuex","archived":false,"fork":false,"pushed_at":"2020-12-14T06:29:56.000Z","size":19,"stargazers_count":104,"open_issues_count":0,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T08:11:19.667Z","etag":null,"topics":["type","type-safety","typescript","vue","vuex"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ktsn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-26T03:49:36.000Z","updated_at":"2023-07-02T11:05:03.000Z","dependencies_parsed_at":"2022-08-15T06:00:54.772Z","dependency_job_id":null,"html_url":"https://github.com/ktsn/vuex-type-helper","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Fvuex-type-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Fvuex-type-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Fvuex-type-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Fvuex-type-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktsn","download_url":"https://codeload.github.com/ktsn/vuex-type-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248574001,"owners_count":21126938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["type","type-safety","typescript","vue","vuex"],"created_at":"2024-08-02T13:02:31.781Z","updated_at":"2025-04-12T13:36:36.771Z","avatar_url":"https://github.com/ktsn.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Vuex Type Helper\n\nType level helper to ensure type safety in Vuex.\n\n## Installation\n\n```bash\n# npm\n$ npm install vuex-type-helper\n\n# yarn\n$ yarn add vuex-type-helper\n```\n\n## Example\n\n```ts\nimport * as Vuex from 'vuex'\nimport { DefineGetters, DefineMutations, DefineActions, Dispatcher, Committer } from 'vuex-type-helper'\n\n/**\n * Declare module types\n */\nexport interface CounterState {\n  count: number\n}\n\nexport interface CounterGetters {\n  // getterName: returnType\n  half: number\n}\n\nexport interface CounterMutations {\n  // mutationName: mutationPayloadType\n  inc: {\n    amount: number\n  }\n  reset: void // having no payload\n}\n\nexport interface CounterActions {\n  // actionName: actionPayloadType\n  incAsync: {\n    amount: number\n    delay: number\n  }\n  reset: void // having no payload\n}\n\n/**\n * Implement the module\n */\nconst state: CounterState = {\n  count: 0\n}\n\nconst getters: DefineGetters\u003cCounterGetters, CounterState\u003e = {\n  half: state =\u003e state.count / 2\n}\n\nconst mutations: DefineMutations\u003cCounterMutations, CounterState\u003e = {\n  inc (state, { amount }) {\n    state.count += amount\n  },\n\n  reset(state) {\n    state.count = 0\n  }\n}\n\nconst actions: DefineActions\u003cCounterActions, CounterState, CounterMutations, CounterGetters\u003e = {\n  incAsync ({ commit }, payload) {\n    setTimeout(() =\u003e {\n      commit('inc', payload)\n    }, payload.delay)\n  },\n\n  reset({ commit }) {\n    commit('reset')\n  }\n}\n\n/**\n * Create a store as same as the ordinary way\n */\nconst store = new Vuex.Store({\n  state,\n  getters,\n  mutations,\n  actions\n})\n\n/**\n * Annotate dispatch/commit type with declared actions/mutations type\n */\nstore.dispatch\u003cDispatcher\u003cCounterActions\u003e\u003e({\n  type: 'incAsync',\n  amount: 1,\n  delay: 1000\n})\n\nstore.dispatch\u003cDispatcher\u003cCounterActions\u003e\u003e({\n  type: 'reset'\n})\n\nstore.commit\u003cCommitter\u003cCounterMutations\u003e\u003e({\n  type: 'inc',\n  amount: 1\n})\n\nstore.commit\u003cCommitter\u003cCounterMutations\u003e\u003e({\n  type: 'reset'\n})\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsn%2Fvuex-type-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktsn%2Fvuex-type-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsn%2Fvuex-type-helper/lists"}