我有很多带有静态变量的类,如下所示:
用户.ts:
export class User {
static modelKey = 'user';
// other variables
}
汽车.ts:
export class Car {
static modelKey = 'car';
// other variables
}
我想在某个地方DataSource
像这样调用(见下文):
const dataSource = new DataSource<Car>();
数据源.ts:
export class DataSource<T> {
constructor() {
console.log(T.modelKey); // won't compile
}
}
当然,它不会编译,因为我不能简单地使用T.<variable>
. 所以,我的问题是:我怎样才能做到这一点?