Closed
Description
Typescript 1.5 adds support for decorators based on the ES7 decorators proposal, and it automatically adds type metadata to classes and properties. It would be nice if the resulting metadata could be used to create SimpleSchema objects. Ideally, I could write something like the following in Typescript:
class Person {
@label('First and last name')
fullName: string;
@label('Date of birth')
dob: Date;
@label('Number of children')
@min(0)
numChildren: number;
}
schema = new SimpleSchema(Person);
And the resulting schema would be equivalent to:
schema = new SimpleSchema({
fullName: {
type: String,
label: 'First and last name'
},
dob: {
type: Date,
label: 'Date of birth'
},
numChildren: {
type: Number,
label: "Number of children",
min: 0
}
});
Is anyone looking into this? Should it be implemented as a separate package, or would a pull request which added support be considered (assuming it doesn't introduce any new dependencies).
The implementation I'm imagining would detect the existence of the Reflect.metadata API and, if it exists, use it to find the metadata and build the schema.
Thoughts?