From 151da14b345afe605aea8ed388ecdfd2659ddf16 Mon Sep 17 00:00:00 2001 From: Abraham Williams <4braham@gmail.com> Date: Thu, 26 Jul 2018 13:52:37 -0500 Subject: [PATCH] Fix tslint errors --- src/index.ts | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5364284..343bb4a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,9 @@ export const Reflection = Object.assign(Reflect, { }); export type Decorator = ClassDecorator | MemberDecorator; -export type MemberDecorator = (target: Target, propertyKey: PropertyKey, descriptor?: TypedPropertyDescriptor) => TypedPropertyDescriptor | void; +export type MemberDecorator = (target: Target, + propertyKey: PropertyKey, + descriptor?: TypedPropertyDescriptor) => TypedPropertyDescriptor | void; export type MetadataKey = string; export type MetadataValue = Function; export type PropertyKey = string | symbol; @@ -16,14 +18,22 @@ export type Target = object | Function; const Metadata = new WeakMap(); -export function defineMetadata(metadataKey: MetadataKey, metadataValue: MetadataValue, target: Target, propertyKey?: PropertyKey) { +export function defineMetadata(metadataKey: MetadataKey, + metadataValue: MetadataValue, + target: Target, propertyKey?: PropertyKey) { return ordinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey); } -export function decorate(decorators: ClassDecorator[], target: Function): Function -export function decorate(decorators: MemberDecorator[], target: object, propertyKey?: PropertyKey, attributes?: PropertyDescriptor): PropertyDescriptor | undefined -export function decorate(decorators: Decorator[], target: Target, propertyKey?: PropertyKey, attributes?: PropertyDescriptor): Function | PropertyDescriptor | undefined { - if (decorators.length === 0) throw new TypeError(); +export function decorate(decorators: ClassDecorator[], target: Function): Function; +export function decorate(decorators: MemberDecorator[], + target: object, + propertyKey?: PropertyKey, + attributes?: PropertyDescriptor): PropertyDescriptor | undefined; +export function decorate(decorators: Decorator[], + target: Target, + propertyKey?: PropertyKey, + attributes?: PropertyDescriptor): Function | PropertyDescriptor | undefined { + if (decorators.length === 0) { throw new TypeError(); } if (typeof target === 'function') { return decorateConstructor(decorators as ClassDecorator[], target); @@ -61,21 +71,29 @@ function decorateConstructor(decorators: ClassDecorator[], target: Function): Fu return target; } -function decorateProperty(decorators: MemberDecorator[], target: Target, propertyKey: PropertyKey, descriptor?: PropertyDescriptor): PropertyDescriptor | undefined { +function decorateProperty(decorators: MemberDecorator[], + target: Target, + propertyKey: PropertyKey, + descriptor?: PropertyDescriptor): PropertyDescriptor | undefined { decorators.reverse().forEach((decorator: MemberDecorator) => { descriptor = decorator(target, propertyKey, descriptor) || descriptor; }); return descriptor; } -function ordinaryDefineOwnMetadata(metadataKey: MetadataKey, metadataValue: MetadataValue, target: Target, propertyKey?: PropertyKey): void { - if (propertyKey && !['string', 'symbol'].includes(typeof propertyKey)) throw new TypeError(); +function ordinaryDefineOwnMetadata(metadataKey: MetadataKey, + metadataValue: MetadataValue, + target: Target, + propertyKey?: PropertyKey): void { + if (propertyKey && !['string', 'symbol'].includes(typeof propertyKey)) { throw new TypeError(); } (getMetadataMap(target, propertyKey) || createMetadataMap(target, propertyKey)) .set(metadataKey, metadataValue); } -function ordinaryGetMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): Function | undefined { +function ordinaryGetMetadata(metadataKey: MetadataKey, + target: Target, + propertyKey?: PropertyKey): Function | undefined { return !!ordinaryGetOwnMetadata(metadataKey, target, propertyKey) ? ordinaryGetOwnMetadata(metadataKey, target, propertyKey) : Object.getPrototypeOf(target) @@ -83,8 +101,10 @@ function ordinaryGetMetadata(metadataKey: MetadataKey, target: Target, propertyK : undefined; } -function ordinaryGetOwnMetadata(metadataKey: MetadataKey, target: Target, propertyKey?: PropertyKey): Function | undefined { - if (target === undefined) throw new TypeError(); +function ordinaryGetOwnMetadata(metadataKey: MetadataKey, + target: Target, + propertyKey?: PropertyKey): Function | undefined { + if (target === undefined) { throw new TypeError(); } const metadataMap = getMetadataMap(target, propertyKey); return metadataMap && metadataMap.get(metadataKey); }