是否可以获取泛型类型的类型名称?

Is it possible to get the type name of a generic type?

我有一个方法签名 execute<TResult>(): Observable<TResult>

如何获取 TResult 类型的名称?

示例:

execute<ViewModel> --> "ViewModel" 是我需要的结果。

据我所知,无法获得TResult的名称,但如果您提供相应的构造函数,您可以获得名称。

声明:

execute<TResult>(ctor: { new (): TResult }) : <TResult> {
  console.log(ctor.name) //Prints out SomeClass
  return <any>null;
}

用法:

execute<SomeClass>(SomeClass);