Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Turn Interface to ObjectNew to Visual Studio Code? Get it now.
Turn Interface to Object

Turn Interface to Object

cause_xl

|
335 installs
| (0) | Free
Turn Typescript Interface to Javascript Object
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

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

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft