Closed
Description
Description
I'd like to propose adding a new field decorator @Alias
In nutshell it's similar to Mongoose alias : while running instanceToPlain
properties which have @Alias({name: "abc"})
decorator are exposed with an alternative property name.
Reverse logic should be applied when running plainToInstance
example:
class User {
@Alias({ name: 'fn'})
firstName: string;
}
const instance = new User();
instance.firstName = 'Alex';
const plain = instanceToPlain(instance, {
useAliases: true,
});
expect(plain.firstName).toEqual(undefined);
expect(plain.fn).toEqual('Alex');
A use case I have in my company: we store JSON objects in DynamoDB, these JSON objects are usually 3-5 KB and have pretty long property names. Amazon charges for each 1 KB written so would be amazing if we could shorten property names in a centralized way and save some cost.