Skip to content

Feature Request: Generate types by the help of existing definitions #20

@boeckMt

Description

@boeckMt

Would it be possible to add an existing file with type definitions as input so only not existing types would be generated.

This would be useful if some generated types are adapted by hand and need to be updated later.

Here a example:

input JSON

{
 "prop1":{
    "name":"",
    "area": 500
  },
  "prop2":{
    "name":"",
    "area": 300
  },
  "prop3": {
    "name":"",
    "area": 400
  }
}

MakeTypes output

export interface MyTestInterface {
  prop1: Prop1OrProp2OrProp3;
  prop2: Prop1OrProp2OrProp3;
  prop3: Prop1OrProp2OrProp3;
}
export interface Prop1OrProp2OrProp3 {
  name: string;
  area: number;
}

Adjusted types by hand

export type PropList = 'prop1' | 'prop2' | 'prop3';

export interface MyTestInterface {
[p in PropList]: Prop;
}
export interface Prop {
  name: string;
  area: number;
}

if then the json would be updated to this

{
 "prop1":{
    "name":"",
    "area": 500,
    "population": 10000
  },
   "prop2":{
    "name":"",
    "area": 300,
    "population": 4000
  },
  "prop3": {
    "name":"",
    "area": 400,
    "population": 8000
  }
}

it should generate

export type PropList = 'prop1' | 'prop2' | 'prop3';

export interface MyTestInterface {
[p in PropList]: Prop;
}
export interface Prop {
  name: string;
  area: number;
  population: number;
}

If you think it's possible i could try to dig into the library and try help coding it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions