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

Actions not recognized when using ActionTree #1461

Closed
farzadmf opened this Issue Nov 28, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@farzadmf

farzadmf commented Nov 28, 2018

Version

3.0.1

Reproduction link

https://github.com/farzadmf/vuex-action-tree-issue

Steps to reproduce

There's no need to run anything, just open the repo in VSCode, and you will see the error. I've added comments to make it clear

What is expected?

When I create an ActionTree<...>, I should be able to call my individual Actions on it

What is actually happening?

When I type my actions to be of type ActionTree<...>, then when I call my action(s), I see the error of "no compatible call signatures"


I've created constants to be used as names for my actions (so that I don't use strings). At first, I though that is what's causing the problem; that's why I created the 'hello()' function to test, and it seems to me the constants are not an issue here.

@ktsn

This comment has been minimized.

Member

ktsn commented Dec 2, 2018

Action type (which is a value of ActionTree object) is a union type of action handler (a function) and action object which is added via #941. You need to manually narrow the type when you annotate your action with ActionTree.

const action = typeSafeActions.hello as Function
action()

@ktsn ktsn closed this Dec 2, 2018

@farzadmf

This comment has been minimized.

farzadmf commented Dec 2, 2018

Thank you @ktsn for your answer. I don't know if I'm missing something here, but I found it too much of a hassle if every time I need to manually specify the type of my action to be able to test them.

Just casting as Function won't work here because my actions need to take an ActionContext<S, R> as the first argument and payload: any as the second argument. It would be much nicer if TypeScript would infer those for me, and I didn't have to manually specify them.

@farzadmf

This comment has been minimized.

farzadmf commented Dec 4, 2018

@kktsn Can you please provide some reference on how to test vuex actions in TypeScript. I saw that there's a type ActionHandler<S, R> (as you mentioned), so I thought maybe I can cast what I have to that, but unfortunately, it's not exported, so I cannot access it.
Of course I can copy/paste what's there and create my own type, but wouldn't it make more sense to use what's already there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment