tokilabs / lang

Extends TypeScript/Javascript with basic classes and functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simplify Expose decorator

yfernandes opened this issue · comments

Currently to expose a property under a different name we have to use

@Expose({ name: 'id' })

Can we make it so we can simply pass a string? e.g. @Expose('id')

The exposed needs to receive which type of option, there are a few different options.
If you can think of a way to do this, please let me know.

The code:

export function Expose(
options?: IF.IExposeOptions
): (object: Object | Function, propertyName?: string) => void {
return CT.Expose(options);
}

The interface:

export interface IExposeOptions {
name?: string;
since?: number;
until?: number;
groups?: string[];
toClassOnly?: boolean;
toPlainOnly?: boolean;
}

While I don't recall the use case I suggested this alternative method, I do remember the number of instances that were used with only the name property were much greater than the instances that had multiple properties set.
So the proposed implementation would be to accept as an options type an IExposeOptions object or a string. If the object were passed the implementation would be the same, if a string was passed, however, we could assume that the string's value referred to the name property

The issue was resolved in the latest version of the package. I will close the issue.