Get keys of a Typescript interface as array of strings

后端 未结 12 1748
攒了一身酷
攒了一身酷 2020-11-28 03:05

I\'ve a lot of tables in Lovefield and their respective Interfaces for what columns they have.
Example:

export interface IMyTable {
  id: number;
  t         


        
12条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 03:45

    You will need to make a class that implements your interface, instantiate it and then use Object.keys(yourObject) to get the properties.

    export class YourClass implements IMyTable {
        ...
    }
    

    then

    let yourObject:YourClass = new YourClass();
    Object.keys(yourObject).forEach((...) => { ... });
    

提交回复
热议问题