项目作者: richie-south

项目描述 :
Generate interfaces on the go! Network request? Then generate interfaces for response!
高级语言: JavaScript
项目地址: git://github.com/richie-south/typescript-type-generator.git
创建时间: 2018-10-31T16:29:09Z
项目社区:https://github.com/richie-south/typescript-type-generator

开源协议:MIT License

下载


typescript-type(interface)-generator

Generate interfaces form javascript objects

install

  1. npm install typescript-interface-generator

example

  1. import { createInterfacesFromObject } from 'typescript-interface-generator'
  2. const code = createInterfacesFromObject(
  3. 'User',
  4. {
  5. id: 1,
  6. data: {
  7. name: 'Richard',
  8. articles: [
  9. {
  10. id: 0,
  11. title: 'article 0',
  12. },
  13. {
  14. id: 0,
  15. title: 'article 0',
  16. },
  17. {
  18. anotherObject: 10,
  19. },
  20. ],
  21. },
  22. }
  23. )
  24. console.log(code)
  25. /**
  26. ** CODE OUTPUT **
  27. interface User {
  28. id: number;
  29. data: Data;
  30. }
  31. interface Data {
  32. name: string;
  33. articles: Array<Articles | Articles1>;
  34. }
  35. interface Articles {
  36. id: number;
  37. title: string;
  38. }
  39. interface Articles1 {
  40. anotherObject: number;
  41. }
  42. */

API

createInterfacesFromObject

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

Syntax

  1. import { createInterfacesFromObject } from 'typescript-interface-generator'
  2. createInterfacesFromObject('NAME', {})

Parameters

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

Return value

string: contains typescript interfaces

gif example