1 Star 0 Fork 0

kaguva / Interface-to-Object

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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

  • right click / hotkey: cmd+shift+J
  • choose [Turn Typescript Interface to Javascript Object] command in the context menu

image

  • That's it!

TODO

  • interface / type in interface

License

MIT License © 2022

MIT License Copyright (c) 2022 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Turn Typescript Interface to Javascript Object 展开 收起
TypeScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/kaguva.agree/Interface-to-Object.git
git@gitee.com:kaguva.agree/Interface-to-Object.git
kaguva.agree
Interface-to-Object
Interface-to-Object
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891