[FEAT]: Handle object type argument in constructor
RNm-dove opened this issue · 3 comments
Description
Hi, this library is so good! Thank you!
I prefer object(dictionary) type argument to multiple arguments in constructor.
Is there any solution ?
import { JsonProperty, Serializable } from 'typescript-json-serializer';
import { Human } from './human';
import { Gender } from './gender';
@Serializable()
export class Father extends Human {
@JsonProperty() public hobby: string;
// object type argument
constructor(args: {
name: string;
id: number;
gender: Gender;
birthDate: Date;
hobby: string;
}) {
super(args.name, args.id, args.gender, args.birthDate);
this.hobby = args.hobby;
}
}
https://stackblitz.com/edit/typescript-rqju2w?file=index.ts
Proposed solution
I think this cloud be done by adding some code.
typescript-json-serializer/src/index.ts
Line 238 in e937426
from
const instance: any = new type();
to
const instance: any = new type({});
Hi, thank you for using my lib!
You are right, I just tested it.
Let me make the modification and I publish a new version really soon!
PS: Just for your information I'm working on a new major version (4.0.0) which comes with lot of breaking changes but with new features and simplication of the use :)
Done, I push a the new 3.4.5 version to npm, tell me if it works for you!
@GillianPerard
It works well !! Thank you!