# All files / decorators/gapi-type-injector gapi-type-injector.ts

72.73% Statements 8/11
100% Branches 2/2
50% Functions 2/4
72.73% Lines 8/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    226x

    3x
    3x
    1x

    3x

    6x

    6x
    3x

     import Container from '../../utils/container/index';

    function InjectTypePrivate<T>(Type) {
        const currentType = new Type();
        if (!Container.has(currentType.name)) {
            Container.set(currentType.name, currentType);
        }
        return Container.get<T>(currentType.name);
    }

    // Beta type injector not working in this moment
    export function TypeInjector<T, K extends keyof T>(Type): Function {
        return function (target: Function, propertyName: string, index?: number) {
            target[propertyName] = InjectTypePrivate(Type);
            target.constructor.prototype[propertyName] = InjectTypePrivate(Type);
        };
    }

    export function InjectType<T, K extends keyof T>(Service): T {
        return InjectTypePrivate<T>(Service);
    }