@a11d/metadata
Version:
A set of behavior-less metadata decorators.
14 lines (13 loc) • 435 B
JavaScript
const key = 'design:type';
/**
* A general-purpose metadata decorator to store the type of a property in runtime.
*/
export function type(type) {
return (target, propertyKey) => {
Reflect.defineMetadata(key, type, target, propertyKey);
};
}
type.get = function (constructor, propertyKey) {
return !constructor ? undefined : Reflect.getMetadata(key, constructor.prototype, propertyKey);
};
globalThis.type = type;