![JSON TO TS](https://camo.githubusercontent.com/dfb867d15928dc2980a247c2ac1946117df6d99ffc9e5edb603e0a1ce6a68d9b/68747470733a2f2f696d6167652e6962622e636f2f66546236306b2f69636f6e2e706e67)
Convert json object to typescript interfaces
const JsonToTS = require("json-to-ts");
const json = {
cats: [{ name: "Kittin" }, { name: "Mittin" }],
favoriteNumber: 42,
favoriteWord: "Hello",
};
JsonToTS(json).forEach((typeInterface) => {
console.log(typeInterface);
});
interface RootObject {
cats: Cat[];
favoriteNumber: number;
favoriteWord: string;
}
interface Cat {
name: string;
}
- Array type merging (Big deal)
- Union types
- Duplicate type prevention
- Optional types
- Array types
$ npm install --save json-to-ts