Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if array of strings matching all interface properties

I have an array of strings that has to match an interface properties names

export interface MyType1 {
  propName1: number;
  propName2: string;
  propNameX: number;
}

tableColumns: string[] = [
  'propName1',
  'propName2',
  'propNameX'
];

Initially I was thinking to convert an interface to an array of strings but haven’t found a solution that works.

So now I am wondering if there anyway to see if array of strings matching an interface or something like that.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve tried using https://github.com/kimamula/ts-transformer-keys but it won’t work in my case as I have no access to webpack configuration, otherwise throwing compiled error in the browser.

Need help.

>Solution :

Quite simply

const tableColumns: (keyof MyType1)[] = [
  'propName1',
  'propName2',
  'propNameX'
];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading