Home > Back-end >  How to DRY two similar typescript interfaces with different key names
How to DRY two similar typescript interfaces with different key names

Time:08-22

I have the same interface in two different formats, a JSON format where the keys are separated by low dash and a javascript camelCase format:

JSON format:

interface MyJsonInterface {
  key_one: string;
  key_two: number;
}

interface MyInterface {
  keyOne: string;
  keyTwo: number;
}

I would like to prevent duplications and don't know the right way to do it. I checked out enter image description here

CodePudding user response:

Using the ideas of the intuitive and readable enter image description here

  • Related