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

Allow decoration of methods with no arguments #25

Open
Maximaximum opened this issue Dec 1, 2021 · 0 comments
Open

Allow decoration of methods with no arguments #25

Maximaximum opened this issue Dec 1, 2021 · 0 comments

Comments

@Maximaximum
Copy link

Please consider this example:

export class DoSomething {
  static readonly type = '[DO SOMETHING]';
}

@Injectable()
export class SomeEffectsClass {
  @Effect(DoSomething)
  doSomething() {
    // Just do something
  }
}

In this case, I get a Typescript compiler error:

Argument of type 'TypedPropertyDescriptor<() => void>' is not assignable to parameter of type 'TypedPropertyDescriptor<(args: DoSomething) => unknown>'.
  Types of property 'set' are incompatible.
    Type '((value: () => void) => void) | undefined' is not assignable to type '((value: (args: DoSomething) => unknown) => void) | undefined'.
      Type '(value: () => void) => void' is not assignable to type '(value: (args: DoSomething) => unknown) => void'.
        Types of parameters 'value' and 'value' are incompatible.ts(2345)

This error can be fixed by adding a parameter to the doSomething method:

export class DoSomething {
    static readonly type = '[DO SOMETHING]';
  }

@Injectable()
export class SomeEffectsClass {
  @Effect(DoSomething)
  doSomething(_: DoSomething) {
    // Just do something
  }
}

However, it does not really make much sense to add a parameter that is not actually used inside the function. Besides, in my case this violates the https://eslint.org/docs/rules/no-unused-vars ESLint rule that I use to make sure no unused function params are declared.

Of course, the eslint warning can be suppressed for each such usage (or it could be disabled globally), but that is suboptimal.

It would be great if the Effects decorator just supported functions with no arguments.

Typescript version: 4.3.5

Maximaximum added a commit to Maximaximum/ngxs-effects that referenced this issue Dec 1, 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