Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
boeckMt opened this issue Sep 29, 2020 · 0 comments
Open

Comments

@boeckMt
Copy link

boeckMt commented Sep 29, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant