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

How to use the makeDecorator with an object as prop #44

Closed
paulhobbel opened this issue Apr 3, 2020 · 1 comment
Closed

How to use the makeDecorator with an object as prop #44

paulhobbel opened this issue Apr 3, 2020 · 1 comment

Comments

@paulhobbel
Copy link

I've been trying to create my own decorators, but don't really have any luck atm.

In angular you can do something like this:

interface ModuleDecorator {
    (module: Module): Module
    new (module: Module): Module
}

interface Module {
    providers: Provider[]
}

const Module = <ModuleDecorator>makeDecorator('Module', (module: Module) => module);

However when doing this with the makeDecorator provided by injection-js the properties are not set to the decorator.

After a quick search I found out this sorta works

const Module = <ModuleDecorator>makeDecorator('Module', ['module']);

However that creates the following

DecoratorFactory {
  module: { providers: [] }
}

Instead, I want the following:

DecoratorFactory {
  providers: []
}
@mgechev
Copy link
Owner

mgechev commented Apr 3, 2020

You can read more about TypeScript decorators here https://www.typescriptlang.org/docs/handbook/decorators.html.

makeDecorator is not a public function of this library.

@mgechev mgechev closed this as completed Apr 3, 2020
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