validate or fatory a type is not a easy thing.
- npm install
npm install --save-dev transform-of-type
import { schemaOf, factoryOf, validatorOf } from "transform-of-type";
interface A {
a: string;
b: number;
}
const schemaString = schemaOf<A>(); // will generate a json-schema string of interface A;
factoryOf<A>().then(factory => {
console.log(factory()); // will generate an object instance of A;
});
validatorOf<A>().then(validate => {
console.log(validate({ a: 1 })); // return false (a is not instance of A);
});