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

Optional parameters in Actions not supported #14

Open
caboe opened this issue Apr 26, 2018 · 1 comment
Open

Optional parameters in Actions not supported #14

caboe opened this issue Apr 26, 2018 · 1 comment

Comments

@caboe
Copy link

caboe commented Apr 26, 2018

Given an action wit optional parameter:
async testIt(context: TestContext, payload?: number): Promise<void> {}

Is mapped with:
export const testAction = dispatch(test.actions.testIt)

When you call the action inside a VUE Component with the optional parameter:
test.testAction(this.$store, 123)

You will get a compile error:
Expected 1 arguments, but got 2.

@CloudNiner
Copy link

I just ran into this issue, but for mutations using the commit() method:

const storeOptions = {
    ...,
    mutations: {
        setSomeValue(state: RootState, someValue?: string) {
            state.someValue = someValue;
        },
        ...
    }
};

export const commitSomeValue = commit(mutations.setSomeValue);

Generates a type signature for commitSomeValue:

const commitSomeValue: (store: ActionContext<RootState, RootState> | Store<RootState>) => void

instead of:

const commitSomeValue: (store: ActionContext<RootState, RootState> | Store<RootState>, someValue: string | undefined) => void

As a workaround, I just changed the types for setSomeValue to:

const setSomeValue: (state: RootState, someValue: string | undefined) => void

instead of using the optional ? syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants