TypeScript: pass generic type as parameter in generic class

后端 未结 3 571
一个人的身影
一个人的身影 2021-01-05 17:23

TypeScript: I have a method in the DataProvider class with a method getTableData:

public static getTableData(ty         


        
3条回答
  •  独厮守ぢ
    2021-01-05 17:37

    Generics are just metadata. They cannot be used as parameters when calling a function. Maybe you need something like this:

    export class ViewModelBase {
      constructor(private Cl: {new(): T}) {
      }
      public getData(): Array {
        return DataProvider.getTableData(this.Cl);
      }
    }
    

提交回复
热议问题