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

前端 未结 1 868
天命终不由人
天命终不由人 2021-01-04 15:56

I have a method signature of execute(): Observable

How do I get the name of the TResult type?

Example:

1条回答
  •  孤独总比滥情好
    2021-01-04 16:15

    As far as I know it is not possible to get the name of TResult, but if you provide the accordingly constructor function you can get the name.

    Declaration:

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

    Usage:

    execute(SomeClass);
    

    0 讨论(0)
提交回复
热议问题