UNPKG

@dipscope/type-manager

Version:

Transform JSON strings or plain objects into JS class instances.

23 lines 1.05 kB
import { nameOf } from './functions/name-of'; import { TypeManager } from './type-manager'; export function Inject(x) { const injectOptions = (typeof x === 'object' ? x : {}); if (injectOptions.key === undefined && typeof x === 'string') { injectOptions.key = x; } if (injectOptions.typeArgument === undefined && typeof x === 'function') { injectOptions.typeArgument = x; } return function (target, propertyName, injectIndex) { if (typeof target === 'function' && target.name === '') { throw new Error(`${nameOf(target.constructor)}.${String(propertyName)}: inject decorator cannot be applied to a method.`); } if (typeof injectIndex !== 'number') { throw new Error(`${nameOf(target)}.${String(propertyName)}: inject decorator cannot be applied to a property.`); } const typeFn = target; TypeManager.configureTypeMetadata(typeFn).configureInjectMetadata(injectIndex, injectOptions); return; }; } //# sourceMappingURL=inject.js.map