Skip to content

Commit

Permalink
馃悰 Add InversifyJS function to make decorators compatible with babel
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardfactory committed Mar 27, 2019
1 parent bb8dc24 commit 4535adb
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion examples/inversify/src/index.ts
Expand Up @@ -14,8 +14,24 @@ let container = new Container();
container.bind<PrintService>('PrintService').to(PrintService);
let { lazyInject } = getDecorators(container);

/**
* Additional function to make properties decorators compatible with babel.
*/
function fixPropertyDecorator<T extends Function>(decorator: T): T {
return ((...args: any[]) => (
target: any,
propertyName: any,
...decoratorArgs: any[]
) => {
decorator(...args)(target, propertyName, ...decoratorArgs);
return Object.getOwnPropertyDescriptor(target, propertyName);
}) as any;
}

const lazyInjectFix = fixPropertyDecorator(lazyInject);

class Book {
@lazyInject('PrintService')
@lazyInjectFix('PrintService')
private printService!: PrintService;

public constructor(public author: string, public summary: string) {}
Expand Down

0 comments on commit 4535adb

Please sign in to comment.