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

Overloading of mutation methods is not correctly typed in Actions #457

Open
vdkrasny opened this issue Jun 24, 2021 · 0 comments
Open

Overloading of mutation methods is not correctly typed in Actions #457

vdkrasny opened this issue Jun 24, 2021 · 0 comments

Comments

@vdkrasny
Copy link
Contributor

vdkrasny commented Jun 24, 2021

First of all, thank you, @ktsn, for a great library! I've been using it for over half a year and it's extremely useful 👍

I've prepared a small example to demonstrate the issue:

import { Getters, Mutations, Actions } from 'vuex-smart-module';

export class TestState {}

export class TestGetters extends Getters<TestState> {}

export class TestMutations extends Mutations<TestState> {
  methodWithOverload(): void;
  methodWithOverload(payload: number): void;
  methodWithOverload(payload: string): void;
  methodWithOverload(payload?: number | string): void {
    // ...
  }

  testMutation() {
    // (method) TestMutations.methodWithOverload(): void (+2 overloads)
    this.methodWithOverload();
    this.methodWithOverload(1);
    this.methodWithOverload('test');
  }
}

export class TestActions extends Actions<TestState, TestGetters, TestMutations, TestActions> {
  testAction() {
    // (method) methodWithOverload(payload?: string | undefined): void
    this.mutations.methodWithOverload();
    this.mutations.methodWithOverload(1); // <-- Argument of type '1' is not assignable to parameter of type 'string | undefined'.
    this.mutations.methodWithOverload('test');
    
    
    this.commit('methodWithOverload');
    this.commit('methodWithOverload', 1); // <-- Argument of type 'number' is not assignable to parameter of type 'string'.
    this.commit('methodWithOverload', 'test');
  }
}

As you can see, when we call methodWithOverload from Actions, its type is not the same as the original.

  • vue: 2.6.11
  • vuex: 3.4.0
  • vuex-smart-module: 0.4.5
  • typescript: 3.9.3
@vdkrasny vdkrasny closed this as completed Oct 4, 2021
@vdkrasny vdkrasny reopened this Oct 4, 2021
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

1 participant