Typescript:在运行时获取类属性的目标类型

时间:2017-07-18 14:01:46

标签: typescript ecmascript-6

我有以下类的示例,并希望将ApiResponse(JSON)转换为我的类型:

class Item_Project {
  public statusAktive: boolean;
  public ProjectName: string;
  public ProjectNumber: number;

  public static fromJSON(jsonObject: Object){
    let t_Project: Item_Project = new Item_Project();
    for(let index in jsonObject){
      if(t_Project.hasOwnProperty(index)){
        if(jsonObject[index] !== undefined && jsonObject[index] !== null) {

          // i need a type check for t_Project[index] here
          // typeof t_Project[index] returns the type of the value not the accepted type

          t_Project[index] = Helper.getTrimmedValue(jsonObject[index]);
        }
      }
    }

  }
}

abstract class Helper {
  public static getTrimmedValue(value): undefined|string|number|boolean {
    // does some magic
  }
}

是否可以检查t_Project [index]属性接受哪种类型转换为注释位置上的右属性?

0 个答案:

没有答案