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