Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useStore is missing a type declaration #1736

Closed
ChrisShank opened this issue Apr 29, 2020 · 4 comments · Fixed by #1739
Closed

useStore is missing a type declaration #1736

ChrisShank opened this issue Apr 29, 2020 · 4 comments · Fixed by #1739
Labels
4.x bug Something isn't working types Related to typings only

Comments

@ChrisShank
Copy link

ChrisShank commented Apr 29, 2020

Version

4.0.0-beta.1

Reproduction link

https://github.com/ChrisShank/vue-next-webpack-preview

Steps to reproduce

Remove the type declaration of 'useStore' I added in 'vuex-shim.d.ts', and there will be a compile-time TS error.

What is expected?

The type for useStore to exist.

What is actually happening?

On the line:

import { useStore } from 'vuex'

There is an error:

TS2614: Module 'vue-next-webpack-preview/node_modules/vuex/types"' has no exported member 'useStore'. Did you mean to use 'import useStore from "vue-next-webpack-preview/node_modules/vuex/types"' instead?
@surmon-china
Copy link

@ChrisShank Override the vuex's type definition in TypeScript.

declare module "vuex" {
  function useStore<T = any>(key?: string): T
}

@surmon-china
Copy link

It seems that the type is difficult to cover, you can do this:

// @ts-ignore
import { createStore, useStore as useVuexStore } from 'vuex'

const store =  createStore<StoreState>({})

export default store
export function useStore(): typeof store {
  return useVuexStore()
}

@ChrisShank
Copy link
Author

@surmon-china I currently am here

I think that a type should either be included with the package (similar to the one you first mentioned) or documented that the user is expected to provide their own shim.

@kiaking
Copy link
Member

kiaking commented Apr 30, 2020

Thanks for the report! Yea we must add this one 👍

@kiaking kiaking added 4.x types Related to typings only bug Something isn't working labels Apr 30, 2020
kiaking added a commit that referenced this issue Apr 30, 2020
@kiaking kiaking linked a pull request Apr 30, 2020 that will close this issue
ktsn pushed a commit that referenced this issue Apr 30, 2020
@kiaking kiaking closed this as completed Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x bug Something isn't working types Related to typings only
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants