There are two class:
class STRING_TYPE {
name():string{
return "one";
}
}
class NUMBER_TYPE {
name():number{
return 1;
}
}
I want to write a generic function:
- create an object of the given class
- call name() method, and return its value; In javascript, code like:
function foo(classType) {
const obj = new classType();
return obj.name();
}
How to write it in typescript?
// it doesn't work.
function foo<T>(typ: T): ReturnType<T.name>{
const obj = new T();
return obj.name();
}