All files / lib/decorators InjectProperty.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 2/2
100% Lines 7/7

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 141x     1x 4x     4x 4x 4x 4x      
import { Keys } from "../Keys";
import { Type } from "../interfaces/IType";
 
export function InjectProperty<I = any>(key: string | Type<I>) {
    return function inject<
        T extends  Record<K, I>,
        K extends string>(target: T, propertyKey: K) {
        const ctr = target.constructor;
        const metadata: any = Reflect.getMetadata(Keys.PROPERTY_INJECT_KEY, ctr) || {};
        metadata[propertyKey] = key;
        Reflect.defineMetadata(Keys.PROPERTY_INJECT_KEY, metadata, ctr);
    };
}