B
B
BonBon Slick2020-06-01 06:50:29
typescript
BonBon Slick, 2020-06-01 06:50:29

Synchronizing return type Vuex module and action?

export default class LayoutDefault extends Vue {
    @user.Action
    public emailTest!: (test: string) => void
// or?
    public emailTest!: (test: string) => Promise<object>


    public mounted(): void {
        console.log(this.emailTest('test2')); // Promise  в любом случае


for this method
@MutationAction
    public async emailTest(test: string): Promise<object> {
        return {email: test};
    }


or separate

@Mutation
    public setEmail(email: string): void {
        this.email = email
    }

    @Action
    public updateName(email: string): void {
        this.context.commit('setEmail', email)
    }


In both cases, whether the action is async or not, and the return type of the action also does not wag, console.log always prints a Promise .

So the questions arose, which return type should be indicated then and where, how to synchronize them?
After all, in fact, there is always a Promise for methods or some other closure. And you also need to specify the same type in 2 places, the return type of the method and in the component when declaring the method
@user.Action
    public emailTest!: (test: string) => Promise<object>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question