CKGrafico / inversify-props

Wrapper of Inversify to inject your dependencies in the components, made with TypeScript and compatible with Vue, React and other component libraries.
MIT License
85 stars 9 forks source link

Error when I use generics #23

Closed michaelzapata closed 4 years ago

michaelzapata commented 4 years ago

Hi

Error when I use generics throw an exception

Uncaught Error: Cannot apply @injectable decorator multiple times. at eval (injectable.js?719e:8) at eval (inject.helper.js?5df8:10) at DecorateConstructor (Reflect.js?98db:541) at Object.decorate (Reflect.js?98db:130) at _decorate (decorator_utils.js?66d7:42) at Object.decorate (decorator_utils.js?66d7:55) at Container.addSingleton (container.js?7644:42) at containerBuilder (app.container.ts?1e2a:26) at new AppModule (main.ts?bc82:13) at eval (main.ts?bc82:30)

This is my code

import { container, injectable } from 'inversify-props';

interface Test {
    id: string;
}

interface TestChild extends Test {
    name: string;
}

interface ServiceInterface<T extends Test> {
    get(): Promise<T>;
}

@injectable()
class Services implements ServiceInterface<TestChild> {
    get(): Promise<TestChild> {
        throw new Error('Method not implemented.');
    }
}

export function containerBuilder(): void {
    container.addSingleton<ServiceInterface<TestChild>>(Services);
}

How can I do to make it work?

webnoob commented 4 years ago

@michaelzapata Are you using version ^2.0.1? If so, see: https://github.com/CKGrafico/inversify-props/issues/21

@injectable has been removed so you no longer need to decorate your service classes.