Closed bukuta closed 5 years ago
Hey @bukuta
Technically, this should be as simple as:
let p1 = new TypedJSON(Person).parse(...);
The problem with the proposed approach is that TypeScript doesn't support type augmentation based on decorators, hence it'll complain that your class does not have a static fromJson
method.
Perhaps instead you could do something like:
class JSONInstantiable {
public static fromJson(json: string) {
return new TypedJSON(this).parse(...);
}
}
And then extend this class to call fromJson
in derived classes.
Thanks for your reply and the solution. You are good man.
TypedJSON is a nice job and i look for it months.
How about adding a decorate like
fromJson
( or with other name)? If a static methodfromJson
is added on the decorated class, then the usage may be a little simpler and easier, likePerson.fromJson(xxx)
instead ofTypedJSON.parse(xxx,Person)
What your opinion?