Why compiler complains the following codes T' only refers to a type, but is being used as a value here:
class Factory<T> {
create(TCreator: (new () => T)): T {
return new TCreator();
}
test(json: string) {
// compile error here:
// T' only refers to a type, but
// is being used as a value here
let a: T = this.create(T);
...
}
}
I don't know.. Shouldn't T be a generic type in the class Factory? And can T be used as the argument of function "create" which has a parameter type as the same as T's constructor type.
I think what I want to do is to create an instance of T in the class Factory. I have tried like let a2: T = new T(); but ran into the same compile error.