UNPKG

@dipscope/type-manager

Version:

Transform JSON strings or plain objects into JS class instances.

23 lines 1.09 kB
import { nameOf } from './functions/name-of'; import { TypeManager } from './type-manager'; export function Inject(x) { var 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("".concat(nameOf(target.constructor), ".").concat(String(propertyName), ": inject decorator cannot be applied to a method.")); } if (typeof injectIndex !== 'number') { throw new Error("".concat(nameOf(target), ".").concat(String(propertyName), ": inject decorator cannot be applied to a property.")); } var typeFn = target; TypeManager.configureTypeMetadata(typeFn).configureInjectMetadata(injectIndex, injectOptions); return; }; } //# sourceMappingURL=inject.js.map