0.0.5 • Published 2 years ago

turn-interface-to-object v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Turn Typescript Interface to Javascript Object

Only support Interface

// some interface definition you have
interface TEST {
  name: string;
  age: number;
  dislike: ["test", "test2"];
  like: string[] | number[];
  info: TEST;
  more: {
    name: string;
    age: number;
    like: string[] | number[];
    test: {
      name: string;
      age: number;
      like: string[] | number[];
    };
  };
};

// this plugin will generate it to javascript object with initial default value
const test = {name: "",age: 0,dislike: [],like: [],info: {},more: {
    name: string;
    age: number;
    like: string[] | number[];
    test: {
      name: string;
      age: number;
      like: string[] | number[];
    };
  },}

Support Extends Keyword (v0.0.5)

interface A extends B {
  a: string;
  c: number;
}
interface B {
  b: string;
  d: boolean;
  e: true;
  f: false;
}

// generated code
const a = {a: "",c: 0,b: "",d: false,e: true,f: false,};

const b = {b: "",d: false,e: true,f: false,};

flaw

  • Cause it may take some effort to support the file system based on extends interface's path
  • You must select the extends Interface alone with the original interface 😣
interface A extends B {
  a: string;
  c: number;
}

// generated code
const a = {a: "",c: 0,};

How to use

  • simply select your interface code

image

image

  • That's it!

TODO

  • interface / type in interface

License

MIT License © 2022