0.0.6 • Published 5 years ago

typescript-interface-generator v0.0.6

Weekly downloads
9
License
ISC
Repository
github
Last release
5 years ago

typescript-type(interface)-generator

Generate interfaces form javascript objects

install

npm install typescript-interface-generator

example

import { createInterfacesFromObject } from 'typescript-interface-generator'

const code = createInterfacesFromObject(
  'User',
  {
    id: 1,
    data: {
      name: 'Richard',
      articles: [
        {
          id: 0,
          title: 'article 0',
        },
        {
          id: 0,
          title: 'article 0',
        },
        {
          anotherObject: 10,
        },
      ],
    },
  }
)

console.log(code)
/**
 ** CODE OUTPUT **

 interface User {
    id: number;
    data: Data;
  }

  interface Data {
    name: string;
    articles: Array<Articles | Articles1>;
  }

  interface Articles {
    id: number;
    title: string;
  }

  interface Articles1 {
    anotherObject: number;
  }
 */

API

createInterfacesFromObject

Takes a name and a javascript object and returns a string with typescript interfaces

Syntax

  import { createInterfacesFromObject } from 'typescript-interface-generator'

  createInterfacesFromObject('NAME', {})

Parameters

  • string
    • name of (parent) interface
  • object
    • object that should be turned to interfaces

Return value

string: contains typescript interfaces

gif example

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago