Imagine you have an existing schema definition object like this:
const schema = { prop1: { type: String, maxLength: 8 }, prop2... };
Now, the challenge is to create a class that can generate documents using properties extracted from the schema without having to declare an interface for each schema object. Is it possible?
You might want something similar to the following in your application:
// schema definition:
const PersonSchema = { name: { type: String, maxLength: 8 } };
// class factory
const PersonClass = SchemaClassFactory(PersonSchema);
// instance with props defined in schema.
let person1 = new PersonClass();
person1.name = 'Jack';
let person2 = new PersonClass();
person2.name = 3; // This should be flagged as an error by tslint.
How can you achieve this functionality efficiently?