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

Action decorator wrong implementation (but working) #27

Open
d0whc3r opened this issue May 11, 2020 · 3 comments
Open

Action decorator wrong implementation (but working) #27

d0whc3r opened this issue May 11, 2020 · 3 comments

Comments

@d0whc3r
Copy link
Contributor

d0whc3r commented May 11, 2020

I have a doubt with Action decorator, here is the source code:

export function Action(options: ActionOptions = {}) {
  return function(target, key: string, descriptor: PropertyDescriptor) {
    if (!options.skipHandler) {
      options.handler = descriptor.value;
    } else {
      delete options.skipHandler;
    }

    (target.actions || (target.actions = {}))[key] = options
      ? {
          ...options
        }
      : options.skipHandler
      ? ""
      : descriptor.value;
  };
}

first if:

  • if options.skipHandler exists, it will be deleted, fair enough

target.actions assignation:

  • if options exists, then { ...options } ELSE check options.skipHandler here is the error, because if options.skipHandler exist is deleted in previous if and you are checking the "else" condition of "if (options)" then, the else condition is that "options" is not defined, then it is not possible that "options.skipHandler" could be defined.

This is giving me a typescript error:

TS2339: Property 'skipHandler' does not exist on type 'never'.

There are some other errors with "noImplicitAny: true" in tsconfig.json that avoid build in projects that are using moleculer-decorators with that config in tsconfig.json, maybe could be useful to add this compilerOptions:

    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": false,
    "noStrictGenericChecks": true,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "resolveJsonModule": true,
    "strict": true,
    "strictNullChecks": true,
@ColonelBundy
Copy link
Owner

Could you supply an example that reproduces your type error?

@d0whc3r
Copy link
Contributor Author

d0whc3r commented May 24, 2020

use the configurarion provided for "tsconfig.json"
add options in tsconfig.json in project

@d0whc3r
Copy link
Contributor Author

d0whc3r commented May 24, 2020

the error is in ternary as I said in the first message, you check "if" options exist, then in else (where "options" does not exists) you call "options.skipHandler"

This is the error. In "else" you could not use "options" because it does not exist

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