From 0ce0e943f578f99aef73eb2303b1e7be359956c9 Mon Sep 17 00:00:00 2001 From: Andrew Kemp Date: Wed, 10 Feb 2021 14:19:37 -0600 Subject: [PATCH] Updating types --- src/decorators/exclude.ts | 6 +++--- src/decorators/memoize.ts | 6 +++--- src/decorators/pluck.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/decorators/exclude.ts b/src/decorators/exclude.ts index bf54ffb..260bc05 100644 --- a/src/decorators/exclude.ts +++ b/src/decorators/exclude.ts @@ -4,13 +4,13 @@ export const EXCLUDED_PROPERTIES_KEY = 'serde:excluded_properties'; /** * Adding this decorator prevents the property from being included in the object built by Serde.serialize() */ -export function Exclude(): Function { - return function (target: any, key: string): void { +export function Exclude(): PropertyDecorator { + return function (target: Object, propertyKey: PropertyKey): void { Reflect.defineMetadata( EXCLUDED_PROPERTIES_KEY, [ ...Reflect.getMetadata(EXCLUDED_PROPERTIES_KEY, target) || [], - key + propertyKey ], target ); diff --git a/src/decorators/memoize.ts b/src/decorators/memoize.ts index 622be24..0c68717 100644 --- a/src/decorators/memoize.ts +++ b/src/decorators/memoize.ts @@ -1,9 +1,9 @@ -export function Memoize(propsToWatch?: string[]): Function { +export function Memoize(propsToWatch?: string[]): MethodDecorator { const hasPropsToWatch = typeof propsToWatch !== 'undefined' && Array.isArray(propsToWatch); if (typeof propsToWatch !== 'undefined' && !hasPropsToWatch) { throw new Error('Somethings wrong with the propsToWatch Array'); } - return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) { + return function(target: Object, propertyKey: PropertyKey, descriptor: PropertyDescriptor) { const originalMethod = descriptor.value; descriptor.value = function(this: any, ...args: any[]) { let modelKeyPart = this; @@ -11,7 +11,7 @@ export function Memoize(propsToWatch?: string[]): Function { const filteredEntries = Object.entries(this).filter(([k,v]) => propsToWatch.includes(k)) modelKeyPart = Object.fromEntries(filteredEntries); } - const reflectKey = `${JSON.stringify(modelKeyPart)}_${JSON.stringify(args)}_${propertyKey}`; + const reflectKey = `${JSON.stringify(modelKeyPart)}_${JSON.stringify(args)}_${String(propertyKey)}`; const hasReflectData = Reflect.hasMetadata(reflectKey, target); if (hasReflectData) { diff --git a/src/decorators/pluck.ts b/src/decorators/pluck.ts index c01b493..52f6541 100644 --- a/src/decorators/pluck.ts +++ b/src/decorators/pluck.ts @@ -6,8 +6,8 @@ export const PLUCK_PROPERTIES_KEY = 'serde:pluck_properties'; * @param field - use 'fieldName' when creating string|number[], * use ['fieldName'] when creating {[fieldName]: value}[] */ -export function Pluck(field: string | string[]): Function { - return function (target: any, key: string): void { +export function Pluck(field: string | string[]): PropertyDecorator { + return function (target: any, key: PropertyKey): void { Reflect.defineMetadata(PLUCK_PROPERTIES_KEY, { ...Reflect.getMetadata(PLUCK_PROPERTIES_KEY, target) || {}, ...{ [key]: field }