Skip to content

Convert jsons to typescript interfaces

Notifications You must be signed in to change notification settings

nilefy/json-to-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

From clipboard

Json to TS

Convert json object to typescript interfaces

Example

Code

const JsonToTS = require('json-to-ts')

const json = {
  cats: [
    {name: 'Kittin'},
    {name: 'Mittin'}
  ],
  favoriteNumber: 42,
  favoriteWord: 'Hello'
}

JsonToTS(json).forEach( typeInterface => {
  console.log(typeInterface)
})

Output:

interface RootObject {
  cats: Cat[];
  favoriteNumber: number;
  favoriteWord: string;
}
interface Cat {
  name: string;
}

Converter

  • Array type merging (Big deal)
  • Union types
  • Duplicate type prevention
  • Optional types
  • Array types

Setup

$ npm install --save json-to-ts

About

Convert jsons to typescript interfaces

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%