Updating types
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user